0027.hs 663 B

123456789101112131415161718192021222324252627282930
  1. import Utils
  2. import Data.List
  3. import Data.Maybe
  4. --import Debug.Trace
  5. --import Text.Printf
  6. numOfPrimes :: Int -> Int -> Int
  7. numOfPrimes a b = go' 0
  8. where
  9. go' :: Int -> Int
  10. go' n
  11. -- | trace (printf "go' n=%-5d r=%-5d" n r) False = undefined
  12. | otherwise = if (isPrime r) then go' (n+1) else n
  13. where r = (n*n) + (a*n) + b
  14. solution :: Int
  15. solution = combinations2 [aDLimit..aULimit] [bDLimit..bULimit]
  16. |> mapFindMaxInitial (uncurry numOfPrimes)
  17. |> (uncurry (*))
  18. where
  19. aULimit = 999
  20. bULimit = 1000
  21. aDLimit = -999
  22. bDLimit = -1000
  23. main :: IO ()
  24. main = putStrLn ("Solution: " ++ show solution)