結果

問題 No.1058 素敵な数
ユーザー betrue12
提出日時 2020-05-22 21:25:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 2,669 ms
コンパイル使用メモリ 202,008 KB
最終ジャッジ日時 2025-01-10 14:08:54
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

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