結果
| 問題 |
No.36 素数が嫌い!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-27 23:55:34 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 5,000 ms |
| コード長 | 780 bytes |
| コンパイル時間 | 615 ms |
| コンパイル使用メモリ | 104,504 KB |
| 実行使用メモリ | 15,516 KB |
| 最終ジャッジ日時 | 2024-06-12 03:47:14 |
| 合計ジャッジ時間 | 2,589 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
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;
}