結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
8,184 KB
testcase_01 AC 66 ms
12,084 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,368 KB
testcase_11 AC 30 ms
6,676 KB
testcase_12 AC 96 ms
16,104 KB
testcase_13 WA -
testcase_14 AC 53 ms
9,988 KB
testcase_15 AC 1 ms
4,368 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 1 ms
4,368 KB
testcase_18 AC 1 ms
4,368 KB
testcase_19 AC 34 ms
7,248 KB
testcase_20 AC 85 ms
15,652 KB
testcase_21 AC 65 ms
12,104 KB
testcase_22 AC 69 ms
12,332 KB
testcase_23 AC 40 ms
8,508 KB
testcase_24 AC 47 ms
9,036 KB
testcase_25 AC 44 ms
8,708 KB
testcase_26 AC 61 ms
9,976 KB
testcase_27 AC 90 ms
14,136 KB
testcase_28 AC 61 ms
9,716 KB
testcase_29 AC 104 ms
15,660 KB
権限があれば一括ダウンロードができます

ソースコード

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 && !isPrime(n / p, pi));

  writeln(r ? "YES" : "NO");
}

bool isPrime(long n, int[] primes)
{
  return primes.all!(p => n % p != 0);
}

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