結果

問題 No.2 素因数ゲーム
ユーザー FF256grhyFF256grhy
提出日時 2015-05-03 22:12:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 322 ms / 5,000 ms
コード長 1,108 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 26,368 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 03:46:23
合計ジャッジ時間 2,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 10 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 180 ms
4,380 KB
testcase_20 AC 121 ms
4,376 KB
testcase_21 AC 322 ms
4,380 KB
testcase_22 AC 10 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 8 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define MAX 100000000

int judge(int);
void factorization(int);
int power(int, int);

int memo[MAX + 1]; // memo[0] は使わない
int factor[9]; // 2*...*23 > MAX (23は9番目の素数)
int exponent[9]; // i番目の素因数の重複度

int main(void) {
	int n;
	scanf("%d", &n);
	factorization(n);
	memo[1] = -1;
	printf("%s\n", judge(n) == 1 ? "Alice" : "Bob");
	return 0;
}

int judge(int n) {
	if(memo[n]) {
		return memo[n];
	}
	int i, j;
	for(i = 0; i < 9; i++) {
		for(j = exponent[i]; 0 < j; j--) { // exponentは0初期化されてるから大丈夫
			exponent[i] -= j;
			int result = judge( n / power(factor[i], j) );
			exponent[i] += j;
			if( result == -1 ) {
				memo[n] = 1;
				return memo[n];
			}
		}
	}
	memo[n] = -1;
	return memo[n];
}

void factorization(int n) {
	int i, cnt = 0;
	for(i = 2; i <= MAX; i++) {
		if(n % i == 0) {
			factor[cnt] = i;
			while(n % i == 0) {
				n /= i;
				exponent[cnt]++;
			}
			cnt++;
		}
		if(n == 1) { break; }
	}
	return;
}

int power(int x, int y) {
	if(y == 0) {
		return 1;
	} else {
		return x * power(x, y - 1);
	}
}
0