結果

問題 No.1058 素敵な数
ユーザー startcppstartcpp
提出日時 2020-05-22 21:30:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 78,032 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 15:56:42
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,944 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