結果

問題 No.36 素数が嫌い!
ユーザー te-shte-sh
提出日時 2016-08-27 23:32:50
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 93,160 KB
実行使用メモリ 16,436 KB
最終ジャッジ日時 2023-09-02 21:30:43
合計ジャッジ時間 3,111 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
8,260 KB
testcase_01 AC 71 ms
13,328 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,372 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 31 ms
6,680 KB
testcase_12 AC 93 ms
15,352 KB
testcase_13 AC 93 ms
16,436 KB
testcase_14 AC 53 ms
10,024 KB
testcase_15 AC 1 ms
4,368 KB
testcase_16 AC 1 ms
4,372 KB
testcase_17 AC 1 ms
4,368 KB
testcase_18 AC 1 ms
4,368 KB
testcase_19 AC 35 ms
7,588 KB
testcase_20 AC 86 ms
15,148 KB
testcase_21 AC 66 ms
12,608 KB
testcase_22 AC 69 ms
12,340 KB
testcase_23 AC 41 ms
8,184 KB
testcase_24 AC 45 ms
8,932 KB
testcase_25 AC 45 ms
9,028 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
}
0