結果
| 問題 | No.12 限定された素数 |
| コンテスト | |
| ユーザー |
aimy
|
| 提出日時 | 2017-06-12 15:48:09 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,142 bytes |
| コンパイル時間 | 4,608 ms |
| コンパイル使用メモリ | 147,712 KB |
| 最終ジャッジ日時 | 2024-11-24 10:03:06 |
| 合計ジャッジ時間 | 4,930 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:3:1: error: [GHC-87110]
Could not load module ‘Data.Set’.
It is a member of the hidden package ‘containers-0.6.8’.
Use -v to see a list of the files searched for.
|
3 | import qualified Data.Set as S
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
import Data.List import Control.Monad import qualified Data.Set as S primes :: [Int] primes = 2 : 3 : [x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x] where isPrime n = null [i | i <- takeWhile (\x -> x^2 <= n) primes, mod n i == 0] main = do getLine as <- map read . words <$> getLine putStrLn $ maybe "-1" show (rprime as) rprime :: [Int] -> Maybe Int rprime as = guard ((not.null) ds) >> maximum ds where sas = S.fromList (concatMap show as) ps = takeWhile (<= 5000000) primes sps = S.fromList ps ips = zip [0..] ps pcands = filter (S.null . flip S.difference sas . S.fromList . show . snd) ips punits = filter ((== sas) . S.fromList . concat . map show) (groupBySeq pcands) ds = map (diffs sps) punits groupBySeq :: [(Int, Int)] -> [[Int]] groupBySeq [] = [] groupBySeq xs@((i,p):ips) = g : groupBySeq (drop (length g) xs) where g = map (snd.snd) $ takeWhile (\(i,(j,_)) -> i==j) (zip [i..] xs) diffs :: S.Set Int -> [Int] -> Maybe Int diffs sps ps = do plb <- (succ <$> S.lookupLT (minimum ps) sps) `mplus` (Just 1) phb <- (pred <$> S.lookupGT (maximum ps) sps) `mplus` (Just 5000000) return (phb - plb)
aimy