{-# OPTIONS_GHC -O2 -fno-cse #-}
module Main where
main = do
primes = 2 : ([3,5..] `minus`
foldi (\(x:xs) -> (x:) . union xs)
[[x*x, x*x+2*x..] | x<- ys])
where
ys = 3 : ([5,7..] `minus`
foldi (\(x:xs) -> (x:) . union xs)
[[x*x, x*x+2*x..] | x<- ys])
foldi f (x:xs) = f x (foldi f (pairs f xs))
pairs f (x:y:t) = f x y : pairs f t
minus
(x:xs
) (y:ys
) = case compare x y
of LT -> x : minus xs (y:ys)
EQ -> minus xs ys
GT -> minus (x:xs) ys
minus a b = a
union
(x:xs
) (y:ys
) = case compare x y
of LT -> x : union xs (y:ys)
EQ -> x : union xs ys
GT -> y : union (x:xs) ys
union a b = a ++ b
ey0jIE9QVElPTlNfR0hDIC1PMiAtZm5vLWNzZSAjLX0KbW9kdWxlIE1haW4gd2hlcmUKCm1haW4gPSBkbyAKICBzPC1nZXRMaW5lCiAgcHJpbnQgJCB0YWtlIDUgJCBkcm9wIChyZWFkIHMtNSkgcHJpbWVzIAoKcHJpbWVzIDo6IFtJbnRdCnByaW1lcyA9IDIgOiAoWzMsNS4uXSBgbWludXNgCiAgICAgICAgICAgICAgIGZvbGRpIChcKHg6eHMpIC0+ICh4OikgLiB1bmlvbiB4cykKICAgICAgICAgICAgICAgICAgICAgW1t4KngsIHgqeCsyKnguLl0gfCB4PC0geXNdKQogd2hlcmUKICB5cyA9IDMgOiAoWzUsNy4uXSBgbWludXNgCiAgICAgICAgICAgICAgIGZvbGRpIChcKHg6eHMpIC0+ICh4OikgLiB1bmlvbiB4cykKICAgICAgICAgICAgICAgICAgICAgW1t4KngsIHgqeCsyKnguLl0gfCB4PC0geXNdKQogIGZvbGRpIGYgKHg6eHMpICA9IGYgeCAoZm9sZGkgZiAocGFpcnMgZiB4cykpCiAgcGFpcnMgZiAoeDp5OnQpID0gZiB4IHkgOiBwYWlycyBmIHQKCm1pbnVzICh4OnhzKSAoeTp5cykgPSBjYXNlIGNvbXBhcmUgeCB5IG9mCiAgICBMVCAtPiB4IDogbWludXMgIHhzICh5OnlzKQogICAgRVEgLT4gICAgIG1pbnVzICB4cyAgICB5cwogICAgR1QgLT4gICAgIG1pbnVzICh4OnhzKSB5cwptaW51cyAgYSAgICAgIGIgICAgID0gYQoKdW5pb24gKHg6eHMpICh5OnlzKSA9IGNhc2UgY29tcGFyZSB4IHkgb2YKICAgIExUIC0+IHggOiB1bmlvbiAgeHMgKHk6eXMpCiAgICBFUSAtPiB4IDogdW5pb24gIHhzICAgIHlzCiAgICBHVCAtPiB5IDogdW5pb24gKHg6eHMpIHlzCnVuaW9uICBhICAgICAgYiAgICAgPSBhICsrIGI=
[1 of 1] Compiling Main ( prog.hs, prog.o )
Linking prog ...
[32452781,32452789,32452837,32452841,32452843]