結果

問題 No.2 素因数ゲーム
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-08-10 18:12:44
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 577 bytes
コンパイル時間 6,564 ms
コンパイル使用メモリ 167,612 KB
実行使用メモリ 20,824 KB
最終ジャッジ日時 2023-09-25 07:55:41
合計ジャッジ時間 15,198 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Bits

main = do
    n <- getLine
    let g = grundy (read n :: Int) $ sieve [2..(read n :: Int)]
    if g /= 0 then print "Alice" else print "Bob"

sieve :: [Int] -> [Int]
sieve [] = []
sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /= 0]

grundy :: Int -> [Int] -> Int
grundy x [] = 0
grundy x (p:ps)
        | cnt == 0 = 0 `xor` grundy x ps
        | otherwise = cnt `xor` (grundy (x `div` (p ^ cnt)) ps)
        where cnt = count x p

count :: Int -> Int -> Int
count x y = case x `mod` y of
                0 -> 1 + count (x `div` y) y
                _ -> 0;
0