結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー btkbtk
提出日時 2016-05-14 09:30:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 1,000 ms
コード長 1,181 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 172,112 KB
実行使用メモリ 41,672 KB
最終ジャッジ日時 2023-08-29 00:58:36
合計ジャッジ時間 3,822 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,384 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 6 ms
6,204 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 15 ms
12,436 KB
testcase_25 AC 15 ms
12,432 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 8 ms
7,472 KB
testcase_30 AC 38 ms
21,700 KB
testcase_31 AC 67 ms
31,916 KB
testcase_32 AC 48 ms
25,252 KB
testcase_33 AC 51 ms
27,128 KB
testcase_34 AC 93 ms
41,672 KB
testcase_35 AC 81 ms
37,528 KB
testcase_36 AC 37 ms
22,720 KB
testcase_37 AC 49 ms
26,164 KB
testcase_38 AC 37 ms
21,536 KB
testcase_39 AC 31 ms
20,196 KB
testcase_40 AC 35 ms
20,980 KB
testcase_41 AC 10 ms
9,700 KB
testcase_42 AC 7 ms
6,864 KB
testcase_43 AC 6 ms
5,456 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0