結果
問題 |
No.371 ぼく悪いプライムじゃないよ
|
ユーザー |
![]() |
提出日時 | 2016-08-24 19:52:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 683 bytes |
コンパイル時間 | 994 ms |
コンパイル使用メモリ | 79,028 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 18:28:25 |
合計ジャッジ時間 | 2,439 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <cmath> using namespace std; int main() { long L, H; cin>>L>>H; const int n=sqrt(H); vector<bool> c(n+1); vector<long> primes; for(long i=2; i<=n; ++i) if (!c[i]) { for(long j=i*i; j<=n; j+=i) c[j]=1; primes.push_back(i); } for(int i=primes.size()-1; i>=0; --i) { auto p=primes[i]; for(auto t=H/p*p; t>=L; t-=p) { if (t<p*p) break; bool ok=true; for(int j=0; ok&&(j<i); ++j) if (t%primes[j]==0) ok=false; if (ok) { cout<<t<<endl; return 0; } } } }