thoga31

Primality of numbers of the form 2n^2-1 (Euler, 216)

Aug 27th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ### Project Euler, problem 216 ### --
  2. isPrime n = all (/= 0) . map (n `mod`) $ [2..squareRoot n]
  3.   where
  4.     squareRoot = truncate . sqrt . fromIntegral
  5.  
  6. list = map (subtract 1 . (*2) . (^2)) [2..]  -- 2n^2-1
  7.  
  8. main = do
  9.   putStrLn . show $ solveit 10000     -- control-case
  10.   putStrLn . show $ solveit 50000000  -- problem
  11.     where
  12.       solveit n = length . filter isPrime $ take (n-1) list
Advertisement
Add Comment
Please, Sign In to add comment