結果

問題 No.300 平方数
ユーザー aimyaimy
提出日時 2017-04-22 21:50:50
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 9,391 ms
コンパイル使用メモリ 160,616 KB
実行使用メモリ 11,404 KB
最終ジャッジ日時 2023-09-28 21:28:29
合計ジャッジ時間 4,432 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,056 KB
testcase_01 AC 3 ms
7,084 KB
testcase_02 WA -
testcase_03 AC 2 ms
7,076 KB
testcase_04 AC 2 ms
6,996 KB
testcase_05 AC 3 ms
7,092 KB
testcase_06 AC 3 ms
6,976 KB
testcase_07 AC 2 ms
7,064 KB
testcase_08 AC 3 ms
7,084 KB
testcase_09 AC 3 ms
6,980 KB
testcase_10 AC 2 ms
7,024 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 133 ms
11,400 KB
testcase_14 AC 2 ms
7,168 KB
testcase_15 WA -
testcase_16 AC 32 ms
11,296 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 22 ms
11,200 KB
testcase_21 AC 33 ms
11,268 KB
testcase_22 WA -
testcase_23 AC 22 ms
11,240 KB
testcase_24 AC 32 ms
11,192 KB
testcase_25 AC 102 ms
11,280 KB
testcase_26 AC 42 ms
11,280 KB
testcase_27 AC 32 ms
11,256 KB
testcase_28 AC 102 ms
11,324 KB
testcase_29 AC 82 ms
11,204 KB
testcase_30 AC 82 ms
11,328 KB
testcase_31 WA -
testcase_32 AC 82 ms
11,308 KB
testcase_33 AC 53 ms
11,404 KB
testcase_34 AC 112 ms
11,288 KB
testcase_35 AC 81 ms
11,336 KB
testcase_36 AC 72 ms
11,364 KB
testcase_37 AC 43 ms
11,284 KB
testcase_38 AC 12 ms
11,212 KB
testcase_39 AC 72 ms
11,268 KB
testcase_40 AC 62 ms
11,348 KB
testcase_41 AC 32 ms
11,264 KB
testcase_42 AC 33 ms
11,268 KB
testcase_43 AC 22 ms
11,288 KB
testcase_44 AC 42 ms
11,256 KB
testcase_45 AC 33 ms
11,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List

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]

isPrime x = null [y | y<-[2..floor (sqrt (fromIntegral x))], mod (y+1) 6 /= 0, mod (y-1) 6 /= 0 , mod x y == 0]

main = readLn >>= print . product . map (\fs -> if odd (length fs) then head fs else 1) . group . factorization

factorization :: Integer -> [Integer]
factorization n = unfoldr fact (n, primes)
 where
  q = (floor . sqrt . fromIntegral) n
  fact (n', pps@(p:ps))
   | n' == 1 = Nothing
   | isPrime n' = Just (n',(1,pps))
   | otherwise = let (d,m) = divMod n' p in if m==0 then Just (p,(d,pps)) else fact (n',ps)
0