結果

問題 No.2 素因数ゲーム
ユーザー NotationNap
提出日時 2015-03-31 04:35:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 995 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 167,144 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 11:04:44
合計ジャッジ時間 3,289 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))

const int MAX_N = 1000000;
bool isp[MAX_N];
vector<int> ps;

map<int, int> memo;

int dp(const int n) {
	if (memo.find(n) != memo.end()) return memo[n];
	if (n == 1) return 0;
	int res = 0;
	vector<int> divs;
	int m = n;
	for (int i = 0; (Int)ps[i] * ps[i] <= m; i++) {
		if (m % ps[i] == 0) {
			divs.push_back(ps[i]);
			do { m /= ps[i]; } while (m % ps[i] == 0);
		}
	}
	if (m > 1) divs.push_back(m);
	REP(i, divs.size()) {
		int d = divs[i];
		int t = n;
		while (t % d == 0) {
			t /= d;
			if (!dp(t)) {
				res = 1;
			}
		}
	}
	return memo[n] = res;
}

int main() {
	int N;
	cin >> N;

	for (int i = 0; i < MAX_N; i++) isp[i] = true;
	isp[0] = isp[1] = false;
	for (int i = 2; i < MAX_N; i++) {
		if (isp[i]) {
			ps.push_back(i);
			for (int j = i + i; j < MAX_N; j += i) isp[j] = false;
		}
	}

	if (dp(N)) cout << "Alice" << endl;
	else cout << "Bob" << endl;

}
0