結果
問題 | No.371 ぼく悪いプライムじゃないよ |
ユーザー |
|
提出日時 | 2016-05-14 00:27:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 183 ms / 1,000 ms |
コード長 | 1,247 bytes |
コンパイル時間 | 827 ms |
コンパイル使用メモリ | 70,316 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 18:05:41 |
合計ジャッジ時間 | 2,899 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 |
ソースコード
#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; auto it = upper_bound(primes.begin(), primes.end(), sqrt(h)); int idx = it - primes.begin(); do { idx--; } while (primes[idx] * primes[idx] > h); do { long long prime2 = primes[idx] * primes[idx]; for (long long i = h; i >= l && i >= prime2; i--) { if (i % primes[idx] == 0) { long long tmp = i / primes[idx]; if (tmp == 1) { continue; } 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; }