結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | guricerin |
提出日時 | 2020-01-15 12:12:01 |
言語 | F# (F# 4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,799 bytes |
コンパイル時間 | 5,753 ms |
コンパイル使用メモリ | 168,992 KB |
実行使用メモリ | 27,824 KB |
最終ジャッジ日時 | 2023-08-30 06:39:00 |
合計ジャッジ時間 | 7,345 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
23,644 KB |
testcase_01 | AC | 75 ms
23,816 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 77 ms
23,768 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 75 ms
23,700 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 76 ms
25,748 KB |
testcase_14 | AC | 77 ms
25,716 KB |
testcase_15 | AC | 76 ms
23,816 KB |
testcase_16 | WA | - |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved.
ソースコード
open System open System.Collections.Generic [<AutoOpen>] module Cin = let read f = stdin.ReadLine() |> f let reada f = stdin.ReadLine().Split() |> Array.map f let readChars() = read string |> Seq.toArray let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString())) [<AutoOpen>] module Cout = let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput())) let print (s: string) = writer.Write s let println (s: string) = writer.WriteLine s let inline puts (s: ^a) = string s |> println module Prime = let inline isPrime (n: int) = let limit = n |> float |> sqrt |> int seq { for p in 2 .. limit do if n % p = 0 then yield () } |> Seq.isEmpty /// nを素因数分解した結果を返す let primeFactors (n: int64): Map<int64, int64> = let limit = n |> float |> sqrt |> int64 let rec count x p acc = if x % p = 0L then count (x / p) p (acc + 1L) else acc let mutable n = n let res = seq { for p in 2L .. limit + 1L do let c = count n p 0L if c <> 0L then let div = (float p) ** (float c) |> int64 n <- n / div yield (p, c) } |> Map.ofSeq if n = 1L then res else res.Add(n, 1L) /// nの約数の個数 let divisorsCount (n: int64): int64 = primeFactors n |> Map.fold (fun acc k v -> acc * (v + 1L)) 1L /// upper以下の素数を列挙 let sieveToUpper upper = seq { yield 2 let knownComposites = System.Collections.Generic.SortedSet<int>() for i in 3 .. 2 .. upper do let found = knownComposites.Contains(i) if not found then yield i for j in i .. i .. upper do knownComposites.Add(j) |> ignore } /// nの約数を列挙(n自身を含む) /// O(log n) let divisors (n: int64): int64 array = let lim = n |> float |> sqrt |> int64 seq { for i in 1L .. lim do if n % i = 0L then yield i if i * i <> n then yield n / i } |> Array.ofSeq |> Array.sort let main() = let n = read int let sieve = Prime.sieveToUpper 10000 seq { for p in sieve do if n = p + 2 || n = p + 3 then yield () } |> fun s -> if s |> Seq.isEmpty then "Lose" else "Win" |> puts () main() writer.Close()