結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー parukiparuki
提出日時 2016-05-13 22:59:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,021 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 175,716 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 16:48:27
合計ジャッジ時間 5,253 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 12 ms
5,376 KB
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 72 ms
5,376 KB
testcase_30 AC 76 ms
5,376 KB
testcase_31 AC 73 ms
5,376 KB
testcase_32 AC 73 ms
5,376 KB
testcase_33 AC 78 ms
5,376 KB
testcase_34 AC 72 ms
5,376 KB
testcase_35 AC 77 ms
5,376 KB
testcase_36 AC 52 ms
5,376 KB
testcase_37 AC 73 ms
5,376 KB
testcase_38 AC 72 ms
5,376 KB
testcase_39 AC 74 ms
5,376 KB
testcase_40 AC 74 ms
5,376 KB
testcase_41 AC 79 ms
5,376 KB
testcase_42 AC 87 ms
5,376 KB
testcase_43 WA -
testcase_44 RE -
testcase_45 AC 3 ms
5,376 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;
}

vector<bool> sieveFlags(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;
    f[2]=1;
    return f;
}

map<ll, int> factorize(ll n){
    map<ll, int> res;
    for(ll i=2; i*i<=n; ++i){
        while(n%i==0){
            n /= i;
            ++res[i];
        }
    }
    if(n!=1) ++res[n];
    return res;
}

ll L, H;

#define LIM 100000

int main(){
    auto ps = sieve(100000);
    auto isp = sieveFlags(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(!isp[i]){
                for(ll j = 2; j*j <= i; ++j){
                    if(i%j == 0){
                        smax(ans, mp(j, i));
                        break;
                    }
                }
            }
        } else{
            rep(i, sz(ps)){
                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;
                }
            }
        }
        cout << ans.second << endl;
    }
}
0