結果

問題 No.1058 素敵な数
ユーザー anubhavchk007anubhavchk007
提出日時 2024-01-11 00:13:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 6,824 ms
コンパイル使用メモリ 253,148 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-11 00:13:24
合計ジャッジ時間 4,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define int long long

void solve(){
    int n;
    cin >> n;

    if (n == 1) {
        cout << 1;
        return;
    }
    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;
            if (!ok) break;
        }
        if (ok) primes.push_back(i);
        if (primes.size() > 100) break; 
    }
    vector<int> a;
    for (int i = 0; i < primes.size(); i++) {
        for (int j = i; j < primes.size(); j++) {
            a.push_back(primes[i] * primes[j]);
        }
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    cout << a[n - 2];
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1;
    // cin >> T;
    while(T--) solve();

    return 0;
}
0