結果

問題 No.1058 素敵な数
ユーザー scol_kpscol_kp
提出日時 2020-05-22 21:42:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,428 bytes
コンパイル時間 2,352 ms
コンパイル使用メモリ 200,800 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 16:24:13
合計ジャッジ時間 2,915 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;

    Vl ps;
    for (ll x = 100001;; x++) {
        bool ok = true;
        for (ll y = 2; y * y <= x; y++) {
            if (x % y == 0) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ps.emplace_back(x);
        }
        if (ps.size() == 10) {
            break;
        }
    }

    Vl vs;
    for (ll i = 0; i < 10; i++) {
        for (ll j = i; j < 10; j++) {
            vs.emplace_back(ps[i] * ps[j]);
        }
    }
    sort(vs.begin(), vs.end());

    if (N == 1) {
        cout << 1 << endl;
    }
    else {
        cout << vs[N - 2] << endl;
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}
0