結果
| 問題 | No.103 素因数ゲーム リターンズ | 
| コンテスト | |
| ユーザー |  koyumeishi | 
| 提出日時 | 2014-12-14 23:37:50 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,369 bytes | 
| コンパイル時間 | 825 ms | 
| コンパイル使用メモリ | 85,800 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-11 21:09:14 | 
| 合計ジャッジ時間 | 1,636 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 20 | 
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
vector<pair<long long, long long> > prime_factorization(long long N){
	vector< pair<long long, long long> > ret;
	
	for(long long i=2; i*i<=N; i++){
		long long tmp = 0;
		while(N%i==0){
			tmp++;
			N/=i;
		}
		if(tmp>0){
			ret.push_back( make_pair(i, tmp) );
		}
	}
	if(N!=1){
		ret.push_back( make_pair(N, 1) );
	}
	return ret;
}
int grundy(vector<int> &memo, int x){
	if(memo[x] >= 0) return memo[x];
	set<int> s;
	auto p = prime_factorization(x);
	for(int i=0; i<p.size(); i++){
		
		s.insert( grundy(memo, x/p[i].first) );
		if(p[i].second >= 2)	s.insert( grundy(memo, x/(p[i].first*p[i].first)) );
	}
	int res = 0;
	while( s.count(res) ) res++;
	memo[x] = res;
	return res;
}
int main(){
	int n;
	cin >> n;
	vector<int> m(n);
	for(int i=0; i<n; i++) cin >> m[i];
	int ans = 0;
	vector<int> memo( *max_element(m.begin(), m.end()) + 1, -1);
	memo[1] = 0;
	
	for(int i=0; i<n; i++){
		ans ^= grundy(memo, m[i]);
	}
	/*
	for(int i=1; i<=*max_element(m.begin(), m.end()); i++){
		cerr << i << " " << memo[i] << endl;
	}
	cerr << endl;
	*/
	cout << (ans==0?"Bob":"Alice") << endl;
	return 0;
}
            
            
            
        