結果
| 問題 | No.103 素因数ゲーム リターンズ | 
| コンテスト | |
| ユーザー |  ふーらくたる | 
| 提出日時 | 2016-08-20 13:22:25 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 5,000 ms | 
| コード長 | 1,013 bytes | 
| コンパイル時間 | 2,568 ms | 
| コンパイル使用メモリ | 72,032 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-07 21:27:19 | 
| 合計ジャッジ時間 | 1,754 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 20 | 
ソースコード
#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;
}
            
            
            
        