結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー はむこはむこ
提出日時 2017-02-08 11:05:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 861 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 150,004 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-26 17:23:06
合計ジャッジ時間 5,583 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
using ll = long long; using vll = vector<ll>; 

int main(void) {
    ll l, h; cin >> l >> h;
    vll primes; 
    vector<bool> is_prime(1e5+10, 1); 
    is_prime[0] = is_prime[1] = 0;
    for (ll p = 2; p < is_prime.size(); p++) if (is_prime[p]) {
        primes.push_back(p);
        for (ll x = p; x < is_prime.size(); x += p) 
            is_prime[x] = 0;
    }
    reverse(primes.begin(), primes.end());

    rep(pi, primes.size()) {
        ll p = primes[pi];
        for (ll x = h / p * p; x >= l; x -= p) 
            if (all_of(primes.begin() + pi + 1, primes.end(), [&](ll y){return x % y;})) {
            // xがp以下の素数を持たない
                cout << x << endl;
                return 0;
            }
    }

    return 0;
}
0