結果

問題 No.1058 素敵な数
ユーザー CELICACELICA
提出日時 2020-09-06 15:16:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 172,268 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 13:58:18
合計ジャッジ時間 2,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;

void mPrime(const unsigned maxelems, vector<ll>& vm)
{
	ll n{1000000};
	vector<bool> v(n, true);
	v[0] = v[1] = false;

	for (ll i = 2; i * i < n; ++i)
	{
		if (v[i])
		{
			for (ll j = 0; i * (j + 2) < n; ++j)
				v[i * (j + 2)] = false;
		}
	}

	for (ul i = 2; i < v.size(); ++i)
	{
		if (v[i] && i > 100000)
			vm.push_back(i);

		if (vm.size() >= maxelems)
			break;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;

	vector<ll> vp;
	mPrime(n, vp);

	vector<ll> vm;
	vm.push_back(1);
	for (int i = 0; i < n - 1; ++i)
		for (int j = i; j < n; ++j)
			vm.push_back(vp[i] * vp[j]);
	sort(vm.begin(), vm.end());

	ll res = vm[n - 1];

	cout << res << "\n";

	return 0;
}
0