結果
| 問題 | No.103 素因数ゲーム リターンズ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-01-27 16:19:59 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1 ms / 5,000 ms | 
| コード長 | 1,073 bytes | 
| コンパイル時間 | 875 ms | 
| コンパイル使用メモリ | 120,196 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-12 06:39:31 | 
| 合計ジャッジ時間 | 1,752 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 20 | 
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;      // math functions
void main()
{
  auto n = readln.chomp.to!size_t;
  auto mi = readln.split.to!(int[]);
  auto maxM = mi.fold!max;
  auto pi = primes(maxM.to!real.sqrt.to!int + 1);
  auto r = mi.map!(m => factors(m, pi)).joiner.map!"a % 3".fold!"a ^ b";
  writeln(r ? "Alice" : "Bob");
}
int[] factors(int n, int[] pi)
{
  int[int] buf;
  while (n > 1) {
    auto f = factor(n, pi);
    ++buf[f];
    n /= f;
  }
  return buf.values;
}
int[] primes(int n)
{
  auto sieve = new bool[]((n + 1) / 2);
  sieve[] = true;
  foreach (p; iota(1, (n.to!real.sqrt.to!int - 1) / 2 + 1))
    if (sieve[p])
      foreach (q; iota(p * 3 + 1, (n + 1) / 2, p * 2 + 1))
        sieve[q] = false;
  auto r = sieve.enumerate
    .filter!("a[1]")
    .map!("a[0]").map!("a * 2 + 1")
    .map!(to!int).array;
  r[0] = 2;
  return r;
}
int factor(int i, int[] pi)
{
  auto ma = i.to!real.sqrt.to!int + 1;
  foreach (p; pi)
    if (p > ma) return i;
    else if (i % p == 0) return p;
  return i;
}
            
            
            
        