結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー treeonetreeone
提出日時 2016-07-08 17:52:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 478 ms / 1,000 ms
コード長 1,129 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 147,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-29 01:09:17
合計ジャッジ時間 9,260 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 12 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 308 ms
4,376 KB
testcase_25 AC 478 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 180 ms
4,376 KB
testcase_30 AC 449 ms
4,376 KB
testcase_31 AC 465 ms
4,376 KB
testcase_32 AC 463 ms
4,376 KB
testcase_33 AC 437 ms
4,376 KB
testcase_34 AC 370 ms
4,376 KB
testcase_35 AC 415 ms
4,376 KB
testcase_36 AC 154 ms
4,380 KB
testcase_37 AC 456 ms
4,376 KB
testcase_38 AC 379 ms
4,380 KB
testcase_39 AC 467 ms
4,376 KB
testcase_40 AC 421 ms
4,380 KB
testcase_41 AC 382 ms
4,376 KB
testcase_42 AC 334 ms
4,380 KB
testcase_43 AC 110 ms
4,376 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

vector<int> prime;
bool isprime[100010];

void sieve(int n){
    rep(i, 0, n + 1) isprime[i] = true;
    isprime[0] = isprime[1] = false;
    rep(i, 2, n + 1){
        if(isprime[i]) prime. push_back(i);
        for(int j = 2*i; j <= n; j += i) isprime[j] = false;
    }
    return;
}

signed main(){
    int l, h, a, ans = -1;
    cin >> l >> h;
    sieve(100000);
    a = prime.back();
    vector<int> cand;

    rep(i, 0, (int)prime.size()){
        int p = h / prime[i];
        while(1){
            if(p < prime[i] || p * prime[i] < l) break;
            bool f = true;
            rep(j, 0, i){
                if(p % prime[j] == 0){
                    f = false; break;
                }
            }
            if(f){
                cand. push_back(prime[i] * p);
                break;
            }
            p--;
        }
    }
    ans = cand.back();
    cout << ans << endl;
}
0