結果

問題 No.1058 素敵な数
ユーザー forest3forest3
提出日時 2020-06-23 15:27:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 172,184 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 18:09:29
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool isPrime( long long x )
{
	if( x < 2 ) return false;
	if( x == 2 ) return true;
	if( x % 2 == 0 ) return false;
	for( long long i = 3; i * i <= x; i += 2 ) {
		if( x % i == 0 ) return false;
	}
	return true;
}

int main()
{
	int N;
	cin >> N;

	long long ans = 1;
	if( N > 1 ) {
		vector<long long> p;
		for( long long i = 100000 + 1; p.size() < N; i++ ) {
			if( isPrime( i ) ) p.push_back( i );
		}
		vector<long long> ans1;
		for( int i = 0; i < N; i++ ) {
			for( int j = 0; j < N; j++ ) {
				ans1.push_back( p[i] * p[j] );
			}
		}
		sort( ans1.begin(), ans1.end() );
		unique( ans1.begin(), ans1.end() );
		ans = ans1[N - 2];
	}

	cout << ans << endl;
}
0