結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-13 23:53:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,211 bytes |
| コンパイル時間 | 656 ms |
| コンパイル使用メモリ | 69,336 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-05 18:34:38 |
| 合計ジャッジ時間 | 2,285 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 WA * 14 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
const int H_MAX_RT = 1e5;
vector<long long> primes;
void make_primes() {
vector<bool> is_prime(H_MAX_RT + 100, true);
is_prime[0] = is_prime[1] = false;
int n = is_prime.size();
for (int i = 2; i < n; i++) {
if (is_prime[i]) {
for (int j = i * 2; j < n; j += i) {
is_prime[j] = false;
}
}
}
for (int i = 0; i < n; i++) {
if (is_prime[i]) {
primes.emplace_back(i);
}
}
}
int main() {
make_primes();
long long l, h;
cin >> l >> h;
long long diff = h - l + 1;
if (diff == 2) {
cout << (l % 2 == 0 ? l : h) << endl;
return 0;
}
auto it = upper_bound(primes.begin(), primes.end(), diff);
int idx = it - primes.begin();
do {
idx--;
} while (primes[idx] * primes[idx] > h);
do {
for (long long i = h; i >= l; i--) {
if (i % primes[idx] == 0) {
long long tmp = i / primes[idx];
bool is_ok = true;
for (int i = 0; i < idx; i++) {
if (tmp % primes[i] == 0) {
is_ok = false;
}
}
if (is_ok) {
cout << i << endl;
return 0;
}
}
}
idx--;
} while (idx > 0);
return 0;
}