結果

問題 No.300 平方数
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-11-13 22:37:17
言語 Haskell
(9.8.2)
結果
AC  
実行時間 73 ms / 1,000 ms
コード長 876 bytes
コンパイル時間 2,759 ms
コンパイル使用メモリ 159,528 KB
実行使用メモリ 16,048 KB
最終ジャッジ日時 2023-10-11 15:56:32
合計ジャッジ時間 5,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,956 KB
testcase_01 AC 3 ms
6,980 KB
testcase_02 AC 3 ms
7,176 KB
testcase_03 AC 2 ms
6,908 KB
testcase_04 AC 2 ms
6,972 KB
testcase_05 AC 2 ms
6,960 KB
testcase_06 AC 3 ms
7,040 KB
testcase_07 AC 3 ms
7,044 KB
testcase_08 AC 2 ms
6,928 KB
testcase_09 AC 3 ms
7,040 KB
testcase_10 AC 2 ms
7,024 KB
testcase_11 AC 3 ms
7,008 KB
testcase_12 AC 2 ms
7,080 KB
testcase_13 AC 73 ms
16,048 KB
testcase_14 AC 3 ms
7,004 KB
testcase_15 AC 3 ms
7,224 KB
testcase_16 AC 3 ms
7,036 KB
testcase_17 AC 2 ms
6,980 KB
testcase_18 AC 3 ms
7,200 KB
testcase_19 AC 3 ms
7,144 KB
testcase_20 AC 4 ms
7,996 KB
testcase_21 AC 2 ms
7,032 KB
testcase_22 AC 3 ms
7,100 KB
testcase_23 AC 7 ms
9,532 KB
testcase_24 AC 22 ms
11,956 KB
testcase_25 AC 62 ms
15,996 KB
testcase_26 AC 22 ms
11,936 KB
testcase_27 AC 22 ms
12,132 KB
testcase_28 AC 52 ms
13,764 KB
testcase_29 AC 42 ms
13,244 KB
testcase_30 AC 5 ms
8,496 KB
testcase_31 AC 6 ms
8,888 KB
testcase_32 AC 6 ms
8,688 KB
testcase_33 AC 32 ms
13,236 KB
testcase_34 AC 62 ms
16,040 KB
testcase_35 AC 42 ms
13,188 KB
testcase_36 AC 22 ms
11,980 KB
testcase_37 AC 23 ms
11,932 KB
testcase_38 AC 3 ms
7,484 KB
testcase_39 AC 3 ms
7,544 KB
testcase_40 AC 3 ms
7,496 KB
testcase_41 AC 22 ms
12,092 KB
testcase_42 AC 3 ms
7,220 KB
testcase_43 AC 4 ms
7,660 KB
testcase_44 AC 3 ms
7,760 KB
testcase_45 AC 3 ms
7,572 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 (group)

primes :: Integral a => [a]
primes = map fromIntegral primes'
    where
        primes' = [2, 3, 5] ++ sieve 5 7 (drop 2 primes')
        sieve m s (p : ps) = [n | n <- ns, gcd m n == 1] ++ sieve (m * p) (p * p) ps
            where ns = [x + y | x <- [s, s + 6 .. p * p - 2], y <- [0, 4]]

factorize :: Integral a => a -> [a]
factorize 1 = []
factorize n = factorize' n primes
    where
        factorize' n ps@(p : pr)
            | p * p > n    = [n]
            | m == 0       = p : factorize' d ps
            | otherwise    = factorize' n pr
            where (d, m) = divMod n p

getY :: Integer -> Integer
getY x = y
    where
        factors = map (\ps -> (head ps, fromIntegral $ length ps)) $ group $ factorize x
        y = product $ map (\(f, k) -> if odd k then f else 1) factors

main :: IO ()
main = print . getY =<< readLn
0