結果

問題 No.2 素因数ゲーム
ユーザー pocaristpocarist
提出日時 2015-08-31 14:29:17
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 2,227 bytes
コンパイル時間 4,569 ms
コンパイル使用メモリ 164,952 KB
実行使用メモリ 25,012 KB
最終ジャッジ日時 2023-09-25 21:01:25
合計ジャッジ時間 8,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
22,944 KB
testcase_01 AC 88 ms
24,912 KB
testcase_02 AC 88 ms
23,008 KB
testcase_03 AC 87 ms
24,952 KB
testcase_04 WA -
testcase_05 AC 86 ms
22,884 KB
testcase_06 WA -
testcase_07 AC 89 ms
24,992 KB
testcase_08 WA -
testcase_09 AC 88 ms
24,920 KB
testcase_10 WA -
testcase_11 AC 90 ms
22,956 KB
testcase_12 AC 88 ms
22,884 KB
testcase_13 WA -
testcase_14 AC 88 ms
23,008 KB
testcase_15 WA -
testcase_16 AC 88 ms
22,860 KB
testcase_17 AC 89 ms
22,952 KB
testcase_18 AC 92 ms
22,952 KB
testcase_19 AC 350 ms
23,008 KB
testcase_20 WA -
testcase_21 AC 565 ms
22,900 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 98 ms
22,944 KB
testcase_26 AC 88 ms
22,952 KB
testcase_27 AC 91 ms
23,012 KB
testcase_28 AC 89 ms
22,928 KB
testcase_29 AC 89 ms
24,948 KB
testcase_30 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 =
        match one, two with
        | true, true -> true
        | false, false -> true
        | true, false -> true
        | false, true -> false
    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) []
//    |> fun a -> dprintfn "%A" a; a
    |> 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
//    |> fun a -> dprintfn "%A" a; a
    |> solve
    |> printfn "%s" 
    0
0