結果

問題 No.1058 素敵な数
ユーザー finefine
提出日時 2020-05-22 23:51:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 168,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 19:29:43
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

template<typename T>
vector<T> sieve(T n) {
    vector<T> res;
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (T i = 2; i <= n; i++) {
        if (!is_prime[i]) continue;
        res.emplace_back(i);
        for (T j = 2 * i; j <= n; j += i) is_prime[j] = false;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    vector<int> v = sieve(200000);
    int n;
    cin >> n;
    if (n == 1) {
        cout << 1 << newl;
        return 0;
    }

    --n;
    int ans = 100000;
    for (int i = 0; i < n; i++) {
        ans = *upper_bound(v.begin(), v.end(), ans);
    }
    cout << ans << newl;
    return 0;
}
0