結果
| 問題 |
No.192 合成数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-31 17:50:26 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 675 bytes |
| コンパイル時間 | 774 ms |
| コンパイル使用メモリ | 123,688 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 04:02:44 |
| 合計ジャッジ時間 | 1,872 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
auto n = readln.chomp.to!int;
auto pi = primes(n + 100);
writeln(iota(n - 100, n + 101).find!(a => a >= 2 && !pi.canFind(a)).front);
}
int[] primes(int n)
{
auto sieve = new bool[](n + 1);
sieve[0..2] = false;
sieve[2..$] = true;
auto max = n.to!real.sqrt.to!int;
foreach (p; 2..max + 1)
if (sieve[p])
foreach (q; iota(p * 2, n + 1, p))
sieve[q] = false;
return sieve.enumerate
.filter!(a => a[1])
.map!(a => a[0].to!int).array;
}