結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
kenjiiiH
|
| 提出日時 | 2016-05-14 17:51:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 918 bytes |
| コンパイル時間 | 847 ms |
| コンパイル使用メモリ | 69,380 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 18:12:58 |
| 合計ジャッジ時間 | 2,260 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
vector<long long> getPrimes(int n) {
vector<bool> ok(n, true);
ok[0] = ok[1]= false;
vector<long long> ret;
for (int i = 2; i < n; i++) {
if (!ok[i])
continue;
ret.push_back(i);
for (int j = i; j < n; j += i)
ok[j] = false;
}
return ret;
}
long long minfac(long long x) {
for (long long d = 2; d * d <= x; d++) {
if (x % d == 0)
return d;
}
return x;
}
int main(int argc, char *argv[])
{
long long l, h;
cin >> l >> h;
vector<long long> ps = getPrimes(150000);
for (int i = ps.size()-1; i >= 0; i--) {
long long x = h / ps[i] * ps[i];
long long lb = max(l, ps[i] * ps[i]);
while (x >= lb) {
long long d = minfac(x / ps[i]);
if (d >= ps[i]) {
cout << x << endl;
return 0;
}
x -= ps[i];
}
}
throw;
}
kenjiiiH