結果

問題 No.2 素因数ゲーム
ユーザー pocaristpocarist
提出日時 2015-08-31 14:19:15
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 2,014 bytes
コンパイル時間 4,981 ms
コンパイル使用メモリ 162,844 KB
実行使用メモリ 25,080 KB
最終ジャッジ日時 2023-09-25 21:00:28
合計ジャッジ時間 10,715 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
22,832 KB
testcase_01 AC 86 ms
20,820 KB
testcase_02 AC 87 ms
24,944 KB
testcase_03 AC 86 ms
25,080 KB
testcase_04 AC 87 ms
23,008 KB
testcase_05 AC 86 ms
20,844 KB
testcase_06 AC 89 ms
25,060 KB
testcase_07 AC 86 ms
20,876 KB
testcase_08 AC 99 ms
22,892 KB
testcase_09 AC 86 ms
22,864 KB
testcase_10 WA -
testcase_11 AC 87 ms
24,924 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 86 ms
22,820 KB
testcase_16 AC 88 ms
24,908 KB
testcase_17 WA -
testcase_18 AC 87 ms
22,856 KB
testcase_19 AC 348 ms
24,980 KB
testcase_20 AC 262 ms
20,824 KB
testcase_21 AC 559 ms
22,864 KB
testcase_22 WA -
testcase_23 AC 87 ms
24,856 KB
testcase_24 AC 86 ms
22,876 KB
testcase_25 AC 97 ms
24,888 KB
testcase_26 AC 86 ms
22,904 KB
testcase_27 WA -
testcase_28 AC 87 ms
22,848 KB
testcase_29 AC 88 ms
20,896 KB
testcase_30 AC 86 ms
22,988 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

// http://yukicoder.me/problems/18
open System

let dprintfn fmt = Printf.kprintf Diagnostics.Debug.WriteLine fmt

    (*
void Calc::decompositPrime(int n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            printf("%d * ", a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    printf("%d\n", n);
}

    *)

module Prime =
    let decomposit n =
        let ans = ref []
        let a = ref 2
        let tmp = ref n
        while !tmp >= !a do
            if !tmp % !a = 0 then
                ans := !a :: !ans
                tmp := !tmp / !a
            else
                incr a
        if !tmp = 1 then !ans
        else !tmp :: !ans

let solve m =
    let one, two = Map.fold (fun (one,two) k v -> match k with
                                                    | 1 -> v%2=0, two
                                                    | 2 -> one, v%2=0
                                                    | _ -> one, two
                        ) (false, false) m
    let ans = one = two
    if ans then "Alice" else "Bob"

[<EntryPoint>]
let main argv = 
    let N = Console.ReadLine() |> int
    Prime.decomposit N
//    |> fun a -> dprintfn "%A" a; a
    |> Seq.fold (fun s t -> 
                    match Map.tryFind t s with
                    | Some v -> Map.add t 2 s
                    | _ -> Map.add t 1 s
                ) Map.empty
//    |> fun a -> dprintfn "%A" a; a
    |> Map.fold (fun s _ v -> v::s) []
    |> Seq.fold (fun s t -> 
                    match Map.tryFind t s with
                    | Some v -> Map.add t (v+1) s
                    | _ -> Map.add t 1 s
                ) Map.empty
    |> solve
    |> printfn "%s" 
    0
0