結果
問題 |
No.371 ぼく悪いプライムじゃないよ
|
ユーザー |
|
提出日時 | 2016-05-22 23:43:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 1,456 bytes |
コンパイル時間 | 1,347 ms |
コンパイル使用メモリ | 109,112 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 18:21:33 |
合計ジャッジ時間 | 2,906 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 |
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> using namespace std; void findPrime(int N, vector<bool>& isPrime) { isPrime.assign(N+1, true); isPrime[0] = isPrime[1] = false; for(int i=2; i*i<=N; i++){ if(isPrime[i]){ for(int j=i; i*j<=N; j++){ isPrime[i*j] = false; } } } } int main() { vector<bool> isPrime; findPrime(100000, isPrime); vector<long long> prime; for(int i=0; i<=100000; ++i){ if(isPrime[i]) prime.push_back(i); } long long a, b; cin >> a >> b; for(long long x=100000; ; --x){ if(!isPrime[x]) continue; for(long long y=b/x; y>=x && y*x>=a; --y){ bool ok = true; for(long long p : prime){ if(p >= x || p * p > y) break; if(y % p == 0){ ok = false; break; } } if(ok){ cout << (x * y) << endl; return 0; } } } }