結果
問題 | No.371 ぼく悪いプライムじゃないよ |
ユーザー |
|
提出日時 | 2016-12-26 15:33:08 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 1,036 bytes |
コンパイル時間 | 962 ms |
コンパイル使用メモリ | 114,304 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 06:06:58 |
合計ジャッジ時間 | 2,253 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { immutable int p_max = 10^^5; bool[p_max] pt; long[] primes; foreach (i; 2..p_max) pt[i] = true; foreach (i; 2..p_max) { if (pt[i]) { primes ~= i; foreach (j; iota(i+i, p_max, i)) pt[j] = false; } } primes.reverse; auto N = primes.length; long L, H; scanf("%lld %lld", &L, &H); foreach (i, p; enumerate(primes)) { if (p > H) continue; for (long j = H/p; (j>=p)&&(p*j>=L); j--) { bool flag = true; foreach (k; iota(N-1, i, -1)) { if (j % primes[k] == 0) { flag = false; break; } } if (flag) { writeln(p * j, " ", ); return; } } } }