結果

問題 No.1058 素敵な数
ユーザー anubhavchk007anubhavchk007
提出日時 2024-01-22 20:23:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 173,288 KB
実行使用メモリ 7,920 KB
最終ジャッジ日時 2024-01-22 20:23:06
合計ジャッジ時間 2,803 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define int long long
vector<int> a;

void solve(){
    int n;
    cin >> n;
    assert(n >= 1 and n <= 5e5);
    if (n == 1) {
        cout << "1\n";
        return;
    }
    cout << a[n - 2] << "\n";
}   

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    vector<int> primes;
    for (int i = 1e5 + 1; ; i++) {
        int ok = 1;
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) {
                ok = 0;
                break;
            }
        }
        if (ok) primes.push_back(i);
        if (primes.size() >= 1001) break;
    }
    int ok = 1;
    for (int i = 0; i < primes.size(); i++) {
        for (int j = i; j < primes.size(); j++) {
            int x = primes[i] * primes[j];
            a.push_back(x);
        }
        if (!ok) break;
    }
    sort(a.begin(), a.end());
    // a.erase(unique(a.begin(), a.end()), a.end());
    int T = 1;
    // cin >> T;
    while(T--) solve();

    return 0;
}
0