結果

問題 No.1058 素敵な数
ユーザー 👑 kmjpkmjp
提出日時 2020-05-22 22:00:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 2,737 ms
コンパイル使用メモリ 203,920 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-15 16:48:09
合計ジャッジ時間 3,070 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

const int prime_max = 1000000;
vector<int> prime;
int NP,divp[prime_max];

void cprime() {
	if(NP) return;
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		//M[i]=NP;
		prime.push_back(i); NP++;
		for(ll j=1LL*i*i;j>=i&&j<prime_max;j+=i) if(divp[j]==0) divp[j]=i;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cprime();
	int N;
	cin>>N;
	if(N==1) {
		cout<<1<<endl;
	}
	else {
		N--;
		vector<ll> V,W;
		FOR(i,NP) {
			if(prime[i]>100000) V.push_back(prime[i]);
			if(V.size()>N) break;
		}
		FOR(x,V.size()) FOR(y,V.size()) W.push_back(V[x]*V[y]);
		sort(ALL(W));
		W.erase(unique(ALL(W)),W.end());
		cout<<W[N-1]<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0