結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
8,212 KB
testcase_01 AC 69 ms
13,028 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 32 ms
5,800 KB
testcase_12 AC 97 ms
16,388 KB
testcase_13 AC 99 ms
14,668 KB
testcase_14 AC 54 ms
10,968 KB
testcase_15 AC 1 ms
4,368 KB
testcase_16 AC 1 ms
4,368 KB
testcase_17 AC 1 ms
4,368 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 35 ms
7,484 KB
testcase_20 AC 89 ms
14,916 KB
testcase_21 AC 67 ms
12,024 KB
testcase_22 AC 69 ms
12,076 KB
testcase_23 AC 42 ms
8,256 KB
testcase_24 AC 49 ms
9,240 KB
testcase_25 AC 45 ms
8,984 KB
testcase_26 AC 65 ms
10,016 KB
testcase_27 AC 81 ms
12,880 KB
testcase_28 AC 65 ms
9,788 KB
testcase_29 AC 93 ms
14,620 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[] pi)
{
  return pi
    .until!(p => p > sqrt(n.to!real).to!int)
    .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