結果

問題 No.300 平方数
ユーザー kuwakuwa
提出日時 2015-12-06 00:10:08
言語 Haskell
(9.8.2)
結果
AC  
実行時間 313 ms / 1,000 ms
コード長 542 bytes
コンパイル時間 1,362 ms
コンパイル使用メモリ 162,412 KB
実行使用メモリ 27,240 KB
最終ジャッジ日時 2023-10-12 15:53:49
合計ジャッジ時間 9,648 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,084 KB
testcase_01 AC 2 ms
7,016 KB
testcase_02 AC 192 ms
21,484 KB
testcase_03 AC 3 ms
6,956 KB
testcase_04 AC 3 ms
7,036 KB
testcase_05 AC 2 ms
7,020 KB
testcase_06 AC 2 ms
7,084 KB
testcase_07 AC 3 ms
7,044 KB
testcase_08 AC 2 ms
7,100 KB
testcase_09 AC 3 ms
7,044 KB
testcase_10 AC 3 ms
7,052 KB
testcase_11 AC 3 ms
7,016 KB
testcase_12 AC 4 ms
8,072 KB
testcase_13 AC 313 ms
27,232 KB
testcase_14 AC 22 ms
12,908 KB
testcase_15 AC 132 ms
18,184 KB
testcase_16 AC 123 ms
17,492 KB
testcase_17 AC 303 ms
27,196 KB
testcase_18 AC 22 ms
12,872 KB
testcase_19 AC 93 ms
14,844 KB
testcase_20 AC 53 ms
13,812 KB
testcase_21 AC 303 ms
27,240 KB
testcase_22 AC 262 ms
24,772 KB
testcase_23 AC 242 ms
23,580 KB
testcase_24 AC 152 ms
19,224 KB
testcase_25 AC 232 ms
23,716 KB
testcase_26 AC 213 ms
22,772 KB
testcase_27 AC 132 ms
18,136 KB
testcase_28 AC 233 ms
24,084 KB
testcase_29 AC 272 ms
26,380 KB
testcase_30 AC 282 ms
25,832 KB
testcase_31 AC 293 ms
27,188 KB
testcase_32 AC 163 ms
19,220 KB
testcase_33 AC 82 ms
15,076 KB
testcase_34 AC 262 ms
24,544 KB
testcase_35 AC 162 ms
19,268 KB
testcase_36 AC 193 ms
21,568 KB
testcase_37 AC 152 ms
19,232 KB
testcase_38 AC 193 ms
19,448 KB
testcase_39 AC 213 ms
22,572 KB
testcase_40 AC 183 ms
17,648 KB
testcase_41 AC 72 ms
13,284 KB
testcase_42 AC 162 ms
19,216 KB
testcase_43 AC 273 ms
24,652 KB
testcase_44 AC 203 ms
21,528 KB
testcase_45 AC 92 ms
14,576 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 Control.Applicative
import Data.List

primes :: [Int]
primes = 2 : [ x | x <- [3,5..],
                null $ filter (\z -> x `mod` z == 0) $ takeWhile (\y -> y^2 <= x) primes]

main :: IO ()
main = do
  x <- read <$> getLine :: IO Int
  print $ solve x

solve :: Int -> Int
solve x = let (g, s) = foldr f (1, x) $ (takeWhile (\z -> z^2<= x) primes)
          in g * s
  where f a (y, m) = let (i, m') = rec a m 0 in (y * i, m')
        rec d z c
          | z `mod` d == 0 = rec d (z `div` d) (1-c)
          | otherwise = (d ^ c, z)
0