結果

問題 No.2 素因数ゲーム
ユーザー ゴリポン先生ゴリポン先生
提出日時 2023-09-13 12:59:35
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 863 bytes
コンパイル時間 3,929 ms
コンパイル使用メモリ 161,840 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-13 12:59:41
合計ジャッジ時間 5,704 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

module main;

import std;
// 蟻本より
// 整数を素数とその指数の組に素因数分解する
alias Factor = Tuple!(long, int);
Factor[] factorize(long x)
{
	Factor[] res;
	
	void addFactor(long n)
	{
		Factor f = Factor(n, 0);
		while (x % n == 0) {
			x /= n;
			++f[1];
		}
		if (f[1]) res ~= f;
	}
	
	addFactor(2);	// まず2で割る
	for (long d = 3; d * d <= x; d += 2) {	// 3以上の奇数で割っていく
		addFactor(d);
	}
	if (x > 1) res ~= Factor(x, 1);	// ここまで残っているxは素数のはず
	
	return res;
}

void main()
{
	// 入力
	auto N = readln.chomp.to!long;
	// 答えの計算と出力
	auto f = factorize(N);
	// このゲームは素因数の指数だけを取り出すとNimとして扱える
	auto game = f.map!(a => a[1]).array;
	int ans = 0.reduce!((a, b) => a ^ b)(game);
	writeln(ans ? "Alice" : "Bob");
}
0