1
0
Fork 0

Problem 75

This commit is contained in:
Jonathan Chan 2017-07-15 08:58:42 -07:00
parent 68f0bc6cb8
commit 61132376f0
4 changed files with 29 additions and 0 deletions

BIN
75 Executable file

Binary file not shown.

BIN
75.hi Normal file

Binary file not shown.

29
75.hs Normal file
View File

@ -0,0 +1,29 @@
import qualified Data.IntMap.Strict as M
import Debug.Trace
bound = 1500000
insertUpdate :: Int -> M.IntMap Int -> M.IntMap Int
insertUpdate k oldMap =
let v = M.findWithDefault 0 k oldMap
in M.insert k (v+1) oldMap
populateMapM :: Int -> Int -> M.IntMap Int -> M.IntMap Int
populateMapM m n intMap =
let p = 2 * m * (m + n)
boundK = floor $ (fromIntegral bound)/(fromIntegral p)
ks = [1..boundK]
in foldr (\k accMap -> insertUpdate (p*k) accMap) intMap ks
populateMap :: Int -> M.IntMap Int -> M.IntMap Int
populateMap m intMap =
let ns = [n | n <- [1..m-1], even (m*n), gcd m n == 1]
in foldr (populateMapM m) intMap ns
singularTriples :: Int
singularTriples =
let boundM = floor . sqrt $ (fromIntegral bound) / 2
finalMap = foldr populateMap M.empty [2..boundM]
in M.size $ M.filter (== 1) finalMap
main = print $ singularTriples

BIN
75.o Normal file

Binary file not shown.