結果

問題 No.1058 素敵な数
ユーザー startcppstartcpp
提出日時 2020-05-22 21:30:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 76,616 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-28 06:30:08
合計ジャッジ時間 1,521 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

bool isPrime[200000];
vector<int> ps;

signed main() {
	int n;
	cin >> n;
	if (n == 1) { cout << 1 << endl; return 0; }
	
	int i, j;
	for (i = 0; i < 200000; i++) isPrime[i] = true;
	isPrime[0] = isPrime[1] = false;
	for (i = 2; i < 200000; i++) {
		if (isPrime[i]) {
			for (j = 2 * i; j < 200000; j += i) {
				isPrime[j] = false;
			}
		}
	}
	for (i = 100001; ps.size() < 10; i++) {
		if (isPrime[i]) {
			ps.push_back(i);
		}
	}
	
	vector<int> vec;
	for (i = 0; i < ps.size(); i++) {
		for (j = 0; j < ps.size(); j++) {
			vec.push_back(ps[i] * ps[j]);
		}
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	
	cout << vec[n - 2] << endl;
	return 0;
}
0