結果
| 問題 | No.371 ぼく悪いプライムじゃないよ |
| コンテスト | |
| ユーザー |
kenjiiiH
|
| 提出日時 | 2016-05-14 17:48:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 917 bytes |
| 記録 | |
| コンパイル時間 | 672 ms |
| コンパイル使用メモリ | 70,140 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-06 02:44:16 |
| 合計ジャッジ時間 | 2,318 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 24 WA * 14 RE * 4 |
ソースコード
#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