結果

問題 No.1058 素敵な数
ユーザー tkmst201tkmst201
提出日時 2021-01-17 09:58:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 207,196 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-08-19 13:47:07
合計ジャッジ時間 3,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 29 ms
7,992 KB
testcase_02 AC 29 ms
8,188 KB
testcase_03 AC 28 ms
7,660 KB
testcase_04 AC 29 ms
7,688 KB
testcase_05 AC 29 ms
8,092 KB
testcase_06 AC 29 ms
7,560 KB
testcase_07 AC 29 ms
7,320 KB
testcase_08 AC 29 ms
8,160 KB
testcase_09 AC 29 ms
8,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

std::vector<int> sieve(int n) {
	std::vector<int> res;
	std::vector<bool> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
		if (!is_prime[i]) continue;
		for (int j = i * i; j <= n; j += i) is_prime[j] = false;
	}
	for (int i = 2; i <= n; ++i) if (is_prime[i]) res.emplace_back(i);
	return res;
}

int main() {
	int N;
	cin >> N;
	if (N == 1) puts("1");
	else {
		vector<int> prime;
		for (int i : sieve(110000)) {
			if (i <= 100000) continue;
			prime.emplace_back(i);
		}
		vector<ll> suteki;
		REP(i, prime.size()) FOR(j, i, prime.size()) suteki.emplace_back((ll)prime[i] * prime[j]);
		sort(ALL(suteki));
		cout << suteki[N - 2] << endl;
	}
}
0