結果

問題 No.103 素因数ゲーム リターンズ
ユーザー ふーらくたるふーらくたる
提出日時 2016-08-20 13:22:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,013 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 72,512 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 10:47:34
合計ジャッジ時間 1,661 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 5 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
using namespace std;

const int MAX_M = 10010;

int grundy[MAX_M];

map<int, int> prime_factorization(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) res[n]++;
    return res;
}

int main() {
    for (int num = 2; num < MAX_M; num++) {
        set<int> s;
        auto factor = prime_factorization(num);
        for (auto it = factor.begin(); it != factor.end(); it++) {
            auto next = num / it->first;
            s.insert(grundy[next]);
            if (it->second >= 2) s.insert(grundy[next / it->first]);
        }

        int g = 0;
        while (s.count(g) != 0) g++;
        grundy[num] = g;
    }

    int n, res = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        res ^= grundy[m];
    }

    if (res) cout << "Alice" << endl;
    else cout << "Bob" << endl;

    return 0;
}
0