結果

問題 No.1058 素敵な数
ユーザー わなわなわなわな
提出日時 2020-05-22 21:45:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 78,316 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 16:28:03
合計ジャッジ時間 1,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool is_prime(int n){//素数判定
    for(int i = 2; i * i < n; i++){
        if(n % i == 0) return false;
    }
    return n != 1;
}
int main(){
    long long N;
    cin >> N;
    if(N == 1){
        cout << 1 << endl;
        return 0;
    }
    N -= 1;
    long long M = 1e5 + 1;
    vector<long long> g;
    int c = 0;
    for(long long i = M;; i+=2){
        if(is_prime(i)) {
            g.push_back(i);
            c++;
        }
        if(c == 10) break;
    }
    vector<long long> t;
    for(long long i = 0; i < g.size(); i++){
        for(long long j = i; j < g.size(); j++){
            t.push_back(g[i]*g[j]);
        }
    }
    sort(t.begin(), t.end());
    cout << t[N - 1] << endl;
}
0