結果
問題 | No.371 ぼく悪いプライムじゃないよ |
ユーザー |
![]() |
提出日時 | 2018-06-24 23:38:16 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,205 bytes |
コンパイル時間 | 993 ms |
コンパイル使用メモリ | 132,060 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-13 01:16:03 |
合計ジャッジ時間 | 16,102 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 WA * 21 |
ソースコード
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ long l = read.to!long; long h = read.to!long; int pmax = 100_000; debug writeln("pmax:", pmax); bool[] isCompound = new bool[](pmax); for(int i = 2; i < pmax; i ++){ if(isCompound[i]) continue; for(int j = i + i; j < pmax; j += i){ isCompound[j] = 1; } } debug writeln("isCompound[0 .. 20]:", isCompound[0 .. 20]); long[] primes = []; for(int p = 2; p < pmax; p ++) if(!isCompound[p]) primes ~= p; debug writeln("primes[0 .. 20]:", primes[0 .. 20]); long[] xs = []; foreach(p; primes){ if(p >= l) break; if(l <= (h / p) * p) xs ~= (h / p) * p; } xs.sort(); debug writeln("xs:", xs); long[] ys; { long y = 0; foreach(x; xs) if(x != y) y = x, ys ~= y; } debug writeln("ys:", ys); long answer = 0; foreach(p; primes){ foreach(i, y; ys) if(y % p == 0){ answer = y; ys[i] = 1; debug writeln("p:", p, " answer:", answer); } } answer.writeln; }