結果

問題 No.2 素因数ゲーム
ユーザー NotationNapNotationNap
提出日時 2015-03-31 04:34:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 999 bytes
コンパイル時間 1,177 ms
コンパイル使用メモリ 154,100 KB
実行使用メモリ 4,972 KB
最終ジャッジ日時 2023-09-17 00:33:54
合計ジャッジ時間 2,633 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,596 KB
testcase_01 AC 9 ms
4,944 KB
testcase_02 AC 9 ms
4,652 KB
testcase_03 AC 9 ms
4,672 KB
testcase_04 WA -
testcase_05 AC 9 ms
4,788 KB
testcase_06 WA -
testcase_07 AC 9 ms
4,732 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 10 ms
4,652 KB
testcase_12 AC 9 ms
4,656 KB
testcase_13 AC 9 ms
4,776 KB
testcase_14 AC 9 ms
4,600 KB
testcase_15 WA -
testcase_16 AC 9 ms
4,608 KB
testcase_17 AC 10 ms
4,652 KB
testcase_18 AC 10 ms
4,788 KB
testcase_19 AC 9 ms
4,716 KB
testcase_20 WA -
testcase_21 AC 10 ms
4,712 KB
testcase_22 AC 9 ms
4,612 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 9 ms
4,768 KB
testcase_26 WA -
testcase_27 AC 9 ms
4,680 KB
testcase_28 WA -
testcase_29 AC 9 ms
4,604 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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 / d)) {
				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