結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー parukiparuki
提出日時 2016-05-13 23:25:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,173 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 170,760 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 17:03:55
合計ジャッジ時間 5,928 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,948 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,948 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 10 ms
6,944 KB
testcase_24 TLE -
testcase_25 WA -
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 64 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 3 ms
6,940 KB
testcase_33 AC 3 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 3 ms
6,944 KB
testcase_41 AC 3 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 TLE -
testcase_44 AC 7 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rt return
#define FOR(i,j,k) for(int i=j; i<(int)k;++i)
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

vector<int> sieve(int n){
    vector<bool> f(n+1);
    for(int i=3; i<=n; i+=2) f[i] = 1;
    for(int i=3; i<=sqrt(n); i+=2) if(f[i]) for(int j=i*3; j<=n; j+=i) f[j] = 0;
    vector<int> res{2};
    for(int i=3; i<=n; i+=2) if(f[i]) res.push_back(i);
    return res;
}

typedef ll Num;
bool isPrime(Num n){
    if(n==1) return 0;
    for(Num i=2; i*i<=n; ++i)
        if(n%i==0) return 0;
    return 1;
}

ll L, H;

#define LIM 2000

int main(){
    auto ps = sieve(100000);
    ios::sync_with_stdio(0);
    cin.tie(0);
    while(cin >> L >> H){
        pair<ll, ll> ans(-1, -1);
        if(H - L <= LIM){
            for(ll i = L; i <= H; ++i)if(!isPrime(i)){
                for(ll j = 2; j*j <= i; ++j){
                    if(i%j == 0){
                        smax(ans, mp(j, i));
                        break;
                    }
                }
            }
        } else{
            while(ps.back()*2ll > H)ps.pop_back();
            for(int i = sz(ps) - 1; i >= 0;--i){
                FOR(j, i, sz(ps)){
                    ll val = (ll)ps[i] * ps[j];
                    if(val <= H && val >= L)smax(ans, mp((ll)ps[i], val));
                    if(val > H)break;

                    ll q = H / val;
                    auto it = lower_bound(ps.begin()+j, ps.end(), q);
                    if(*it*ps[i] * ps[j] > H && it != ps.begin())--it;
                    ll val2 = *it*ps[i] * ps[j];
                    if(*it >= ps[j] && val2 >= L && val2 <= H)
                        smax(ans, mp((ll)ps[i], val2));
                }
                if(ans.first != -1)break;
            }
        }
        cout << ans.second << endl;
    }
}
0