結果

問題 No.1058 素敵な数
ユーザー mikianaaamikianaaa
提出日時 2020-08-27 10:59:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,156 bytes
コンパイル時間 1,837 ms
コンパイル使用メモリ 170,628 KB
実行使用メモリ 7,240 KB
最終ジャッジ日時 2024-04-25 05:31:05
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 12 ms
7,168 KB
testcase_02 AC 12 ms
7,060 KB
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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    int N;
    cin >> N;
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }

    N -= 1;
    int MAX = pow(10, 6);
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i])
            continue;
        for (int j = 2 * i; j < MAX; j += i) {
            is_prime[j] = 0;
        }
    }

    vector<ll> ans, res;
    int cnt = 0;
    for (ll i = pow(10, 5) + 1; i < MAX; i++) {
        if (is_prime[i]) {
            ans.push_back(i);
            cnt++;
        }
        if (cnt == 15) {
            break;
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        for (int j = 0; j < ans.size(); j++) {
            res.push_back(ans[i] * ans[j]);
        }
    }

    sort(all(res));

    cout << res[N - 1] << endl;
}
0