fork download
  1. import Data.List
  2.  
  3. pairs ((x:xs):ys:t) = (x : union xs ys) : pairs t
  4.  
  5. primesTMWE = 2:3:5:7: gapsW 11 wheel (joinT3 $ rollW 11 wheel primes')
  6. where
  7. primes' = 11: gapsW 13 (tail wheel) (joinT3 $ rollW 11 wheel primes')
  8.  
  9. gapsW k ws@(w:t) cs@(c:u) | k==c = gapsW (k+w) t u
  10. | True = k : gapsW (k+w) t cs
  11. rollW k ws@(w:t) ps@(p:u) | k==p = scanl (\c d->c+p*d) (p*p) ws
  12. : rollW (k+w) t u
  13. | True = rollW (k+w) t ps
  14. joinT3 ((x:xs): ~(ys:zs:t)) = x : union xs (union ys zs)
  15. `union` joinT3 (pairs t)
  16. wheel = 2:4:2:4:6:2:6:4:2:4:6:6:2:6:4:2:6:4:6:8:4:2:4:2:
  17. 4:8:6:4:6:2:4:6:2:6:6:4:2:4:6:2:6:4:2:4:2:10:2:10:wheel
  18.  
  19. iSqrt :: Integer -> Integer
  20. iSqrt = floor . sqrt . (fromIntegral :: Integer -> Double)
  21. -- isPrime n = n == head (primeFactors n)
  22. isPrime n = (and (map f [3, 5..iSqrt n])) && (n `mod` 2) /= 0
  23. where f x = (n `mod` x) /= 0
  24.  
  25. --uses fastest algorithm I could find for prime number generation
  26. p50 = p (filter (<= 1000001) primesTMWE) 2 2
  27. where p [] _ z = z
  28. p (x:xs) a z
  29. | isPrime (x + a) = p xs (x + a) (x + a)
  30. | otherwise = p xs (x + a) z
  31.  
  32. main = do
  33. putStrLn $ show p50
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:69: warning: missing terminating ' character
prog.cpp:5: error: missing terminating ' character
prog.cpp:7:11: warning: character constant too long for its type
prog.cpp:9: error: stray ‘@’ in program
prog.cpp:9: error: stray ‘@’ in program
prog.cpp:11: error: stray ‘@’ in program
prog.cpp:11: error: stray ‘@’ in program
prog.cpp:11: error: stray ‘\’ in program
prog.cpp:15: error: stray ‘`’ in program
prog.cpp:15: error: stray ‘`’ in program
prog.cpp:22:29: error: too many decimal points in number
prog.cpp:22: error: stray ‘`’ in program
prog.cpp:22: error: stray ‘`’ in program
prog.cpp:23: error: stray ‘`’ in program
prog.cpp:23: error: stray ‘`’ in program
prog.cpp:1: error: ‘import’ does not name a type
stdout
Standard output is empty