Problem 27

http://projecteuler.net/index.php?section=problems&id=27
n^2 + an + bという式があったとする。 |a| <= 1000、|b| <= 1000の中で
nを0からmまで、全て素数となり、かつmが最大となるa と b の組の積を求めよ。

import Prime (isPrime, primes)
import Data.List (maximumBy)

main = print $ f $ maximumBy (\(_, x) (_, y) -> x `compare` y) $ map g coefficients
    where f ((a, b), _) = a * b
          g pair        = (pair, length $ consecutivePrimes pair)

consecutivePrimes (a, b) = takeWhile isPrime $ map f [0..]
    where f n = n * n + a * n + b

coefficients = [(a, b) | a <- [-999..999], b <- takeWhile (< 1000) primes, isPrime (1 + a + b)]

n^2 -61 * n + 971 が 長さ71。

971,911,853,797,743,691,641,593,547,503,
461,421,383,347,313,281,251,223,197,173,
151,131,113,97,83,71,61,53,47,43,
41,41,43,47,53,61,71,83,97,113,
131,151,173,197,223,251,281,313,347,383,
421,461,503,547,593,641,691,743,797,853,
911,971,1033,1097,1163,1231,1301,1373,1447,1523,
1601