結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-19 22:35:13 |
| 言語 | F# (F# 4.0) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 912 bytes |
| コンパイル時間 | 15,219 ms |
| コンパイル使用メモリ | 193,452 KB |
| 実行使用メモリ | 41,228 KB |
| 最終ジャッジ日時 | 2024-10-09 16:33:31 |
| 合計ジャッジ時間 | 22,455 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 17 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (329 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/
ソースコード
#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 プライムナンバーゲーム`` ()