結果

問題 No.1058 素敵な数
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-07-19 23:38:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,208 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 104,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-09 23:48:44
合計ジャッジ時間 3,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:78:20: warning: 'n' may be used uninitialized [-Wmaybe-uninitialized]
   78 |         cout<<ans[n-1]<<endl;
      |                   ~^~
main.cpp:59:13: note: 'n' was declared here
   59 |         int n;
      |             ^

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;

const int inf = (int)1e9; 

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

bool prime[1000010];
void furui() {
	int i = 2;
	while (i <= 1000000) {
		int j = 2;
		while (j*j <= i && !prime[i]) {
			if (i%j == 0) {
				prime[i] = true;
				break;
			}
			else j++;
		}
		int z = 2;
		while (!prime[i]) {
			if (i*z <= 1000000) {
				prime[i*z] = true;
				z++;
			}
			else break;
		}
		i++;
	}
}

int main(void){
	int n;
	furui();
	int num = 0;
	vector<ll>X;
	for(ll i=100001;;i++){
		if(!prime[i]){
			X.push_back(i);
			num++;
		}
		if(num==10)break;
	}
	vector<ll>ans;
	for(ll i=0;i<X.size();i++){
		for(ll j=0;j<X.size();j++){
			ans.push_back(X[i]*X[j]);
		}
	}
	ans.push_back(1);
	sort(ans.begin(),ans.end());
	cout<<ans[n-1]<<endl;
	return 0;
}
0