結果

問題 No.7 プライムナンバーゲーム
ユーザー regeregeregerege
提出日時 2015-10-19 22:35:13
言語 F#
(F# 4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 912 bytes
コンパイル時間 13,981 ms
コンパイル使用メモリ 193,728 KB
実行使用メモリ 41,316 KB
最終ジャッジ日時 2024-04-17 22:51:06
合計ジャッジ時間 15,614 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (394 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

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 f N =
        let dp = [| yield 1; yield 1; for i in 2..N -> 0; |]
        let ps = primes |> Seq.takeWhile ((>=)N) |> Seq.toList
        let rec f i = function
            | p::ps ->
                if p <= i then
                    if dp.[i-p] = 0 then dp.[i] <- 1
                    else f i ps
            | [] -> ()
        for i in 2..N do f i ps
        dp.[N]
    printfn "%s" ["Lose";"Win"].[f (int(stdin.ReadLine()))]
``No.7 プライムナンバーゲーム`` ()
0