結果
| 問題 |
No.103 素因数ゲーム リターンズ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-05 16:02:12 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 975 bytes |
| コンパイル時間 | 920 ms |
| コンパイル使用メモリ | 129,440 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 04:11:01 |
| 合計ジャッジ時間 | 1,903 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
auto n = readln.chomp.to!int;
auto mi = readln.split.map!(to!int);
auto pi = primes(mi.reduce!(max));
auto qi = mi.map!(m => calc(m, pi)).reduce!("a ~ b");
writeln(qi.map!("a % 3").reduce!("a ^ b") == 0 ? "Bob" : "Alice");
}
int[] calc(int n, int[] pi)
{
int[] r;
int i = 0;
while (n > 1) {
auto s = 0;
while (n % pi[i] == 0) {
s += 1;
n /= pi[i];
}
if (s > 0) r ~= s;
i += 1;
}
return r;
}
int[] primes(int n)
{
auto sieve = new bool[](n + 1);
sieve[0..2] = false;
sieve[2..$] = true;
foreach (p; 2..n.to!real.sqrt.to!int + 1)
if (sieve[p])
foreach (q; iota(p * 2, n + 1, p))
sieve[q] = false;
return sieve.enumerate
.filter!("a[1]")
.map!("a[0]").map!(to!int).array;
}