結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2016-05-14 09:30:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 1,000 ms |
| コード長 | 1,181 bytes |
| コンパイル時間 | 2,070 ms |
| コンパイル使用メモリ | 173,652 KB |
| 実行使用メモリ | 41,728 KB |
| 最終ジャッジ日時 | 2024-12-30 18:11:23 |
| 合計ジャッジ時間 | 4,454 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
vector<LL> prime;
struct eratosthenes{
eratosthenes(){
vector<bool> used(110001,true);
for(int i = 2; i*i <= 110000; i++){
if(used[i]){
for(int j = i+i; j <= 110000; j+=i)
used[j]=false;
}
}
for(int i = 2; i <= 110000; i++){
if(used[i])prime.push_back(i);
}
}
}e;
int main() {
LL L,H;
cin >> L >> H;
LL b=0;
for(; prime[b]*prime[b] <= H; b++);
b--;
LL c=b;
for(; prime[b]*prime[c] <= H; c++);
c--;
L=max(L,prime[b]*prime[c]);
int sz=H-L+1;
vector<pair<LL,LL>> res(sz,pair<LL,LL>(114514,0));
for(int i = 0; i < sz; i++)
res[i].second=L+i;
for(auto& p : prime){
LL d=(L+p-1)/p;
d=d*p-L;
for(int i = d;i < sz; i+=p)
if(res[i].second!=p)
res[i].first=min(res[i].first,p);
}
pair<LL,LL> ans;
for(auto& it : res){
if(it.first!=114514)ans=max(ans,it);
}
cout << ans.second << endl;
return 0;
}
btk