結果

問題 No.2 素因数ゲーム
ユーザー NotationNapNotationNap
提出日時 2015-03-31 04:35:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 995 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 153,716 KB
実行使用メモリ 4,936 KB
最終ジャッジ日時 2023-08-27 03:42:36
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,604 KB
testcase_01 AC 10 ms
4,716 KB
testcase_02 AC 10 ms
4,732 KB
testcase_03 AC 9 ms
4,616 KB
testcase_04 AC 10 ms
4,936 KB
testcase_05 AC 10 ms
4,932 KB
testcase_06 AC 10 ms
4,792 KB
testcase_07 AC 10 ms
4,584 KB
testcase_08 AC 9 ms
4,772 KB
testcase_09 AC 10 ms
4,804 KB
testcase_10 AC 10 ms
4,652 KB
testcase_11 AC 10 ms
4,768 KB
testcase_12 AC 10 ms
4,636 KB
testcase_13 AC 10 ms
4,680 KB
testcase_14 AC 10 ms
4,792 KB
testcase_15 AC 10 ms
4,636 KB
testcase_16 AC 10 ms
4,736 KB
testcase_17 AC 9 ms
4,760 KB
testcase_18 AC 10 ms
4,592 KB
testcase_19 AC 10 ms
4,612 KB
testcase_20 AC 10 ms
4,640 KB
testcase_21 AC 10 ms
4,588 KB
testcase_22 AC 9 ms
4,764 KB
testcase_23 AC 10 ms
4,664 KB
testcase_24 AC 10 ms
4,792 KB
testcase_25 AC 10 ms
4,592 KB
testcase_26 AC 10 ms
4,768 KB
testcase_27 AC 9 ms
4,700 KB
testcase_28 AC 10 ms
4,936 KB
testcase_29 AC 9 ms
4,764 KB
testcase_30 AC 9 ms
4,636 KB
権限があれば一括ダウンロードができます

ソースコード

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