結果

問題 No.7 プライムナンバーゲーム
ユーザー regeregeregerege
提出日時 2015-10-18 13:35:10
言語 F#
(F# 4.0)
結果
RE  
実行時間 -
コード長 831 bytes
コンパイル時間 4,831 ms
コンパイル使用メモリ 158,576 KB
実行使用メモリ 25,184 KB
最終ジャッジ日時 2023-09-28 22:06:44
合計ジャッジ時間 7,887 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

#nowarn "40"
let ``No.7 プライムナンバーゲーム`` () =
    let rec primes = 
        Seq.cache <| seq { yield 2; yield! Seq.unfold nextPrime 3 }
    and nextPrime n =
        if isPrime n then Some(n, n + 2) else nextPrime(n + 2)
    and isPrime n =
        if n >= 2 then
            primes
            |> Seq.tryFind (fun x -> n % x = 0 || x * x > n)
            |> fun x -> x.Value * x.Value > n
        else false
    let N = int <| stdin.ReadLine()
    // 素数による分割数
    let p n = primes |> Seq.item n
    let rec pd m =
        let dp = Array.init (m+1) (fun _ -> 0)
        dp.[0] <- 1
        for a in 0..m do
            for b in (p a)..m do
                dp.[b] <- dp.[b] + dp.[b - p a]
        dp.[m]
    printfn "%s" ["Win";"Lose";].[(pd N) &&& 1]
``No.7 プライムナンバーゲーム`` ()
0