TLE,求助

import Control.Monad (forM_, join)

main :: IO ()
main = join $ getLine >>= return . map read . words >>= return . \[m, n] ->
         let p1 = primesBounded n
             p2 = dropWhile (< m) p1
             p3 = filter isPalindromic p2
          in forM_ p3 print

primesBounded :: Integral a => a -> [a]
primesBounded m = 2 : filterPrimes [3, 5..m]
  where filterPrimes all@(x : xs)
          | x > bound = all
          | otherwise = x : filterPrimes (filter (\n -> n `mod` x /= 0) xs)
        bound = floor $ sqrt $ fromIntegral m

isPalindromic :: Show a => a -> Bool
isPalindromic n = let s = show n in s == reverse s

1 条评论

  • 1

信息

ID
1042
难度
7
分类
搜索 | 搜索与剪枝 点击显示
标签
(无)
递交数
6601
已通过
1521
通过率
23%
被复制
13
上传者