結果
| 問題 | 
                            No.36 素数が嫌い!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-08-27 23:32:50 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 658 bytes | 
| コンパイル時間 | 743 ms | 
| コンパイル使用メモリ | 104,072 KB | 
| 実行使用メモリ | 15,672 KB | 
| 最終ジャッジ日時 | 2024-06-12 03:47:05 | 
| 合計ジャッジ時間 | 2,915 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 19 WA * 7 | 
ソースコード
import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv, std.math;
import std.stdio, std.typecons;
void main()
{
  auto n = readln.chomp.to!long;
  auto max = sqrt(n.to!real).to!int;
  auto pi = primes(max);
  auto r = pi.any!(p => n % p == 0 && !pi.canFind(n / p));
  writeln(r ? "YES" : "NO");
}
int[] primes(int n)
{
  auto sieve = new bool[n + 1];
  sieve.fill(true);
  auto max = sqrt(n.to!real).to!int;
  for (auto p = 2; p <= max; ++p)
    if (sieve[p])
      for (auto q = p * 2; q <= n; q += p)
        sieve[q] = false;
  int[] r;
  for (auto p = 2; p <= n; ++p)
    if (sieve[p])
      r ~= p;
  return r;
}