結果

問題 No.1058 素敵な数
ユーザー mikianaaamikianaaa
提出日時 2020-08-27 10:59:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,156 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 173,712 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-11-07 15:33:09
合計ジャッジ時間 2,335 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 7
権限があれば一括ダウンロードができます

ソースコード

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