結果

問題 No.1058 素敵な数
ユーザー betrue12betrue12
提出日時 2020-05-22 21:25:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 2,565 ms
コンパイル使用メモリ 204,712 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 15:43:45
合計ジャッジ時間 3,023 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

vector<int64_t> sieve(int n){
    vector<int64_t> ret;
    vector<bool> is_prime(n+1);
    for(int i=2; i<=n; i++) is_prime[i] = true;
    for(int i=2; i<=n; i++){
        if(is_prime[i]){
            if(i > 1e5) ret.push_back(i);
            for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
        }
    }
    return ret;
}

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

int main(){
    int N;
    cin >> N;
    auto primes = sieve(110000);
    vector<int64_t> cand;
    cand.push_back(1);
    for(int i=0; i<10; i++) for(int j=0; j<10; j++) cand.push_back(primes[i]*primes[j]);
    cand = compress(cand);
    cout << cand[N-1] << endl;
    return 0;
}
0