結果
| 問題 |
No.1058 素敵な数
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2020-05-23 17:52:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,502 bytes |
| コンパイル時間 | 1,036 ms |
| コンパイル使用メモリ | 97,316 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-08 15:42:09 |
| 合計ジャッジ時間 | 1,737 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1058.cc: No.1058 素敵な数 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 10;
const int MAX_M = MAX_N * MAX_N;
const int MAX_P = 100200;
/* typedef */
typedef long long ll;
/* global variables */
bool primes[MAX_P + 1];
int pnums[MAX_P];
ll as[MAX_M];
/* subroutines */
int gen_primes(int maxp, int pnums[]) {
memset(primes, true, sizeof(primes));
primes[0] = primes[1] = false;
int p, pn = 0;
for (p = 2; p * p <= maxp; p++)
if (primes[p]) {
pnums[pn++] = p;
for (int q = p * p; q <= maxp; q += p) primes[q] = false;
}
for (; p <= maxp; p++)
if (primes[p]) pnums[pn++] = p;
return pn;
}
/* main */
int main() {
int pn = gen_primes(MAX_P, pnums);
//printf("pn=%d\n", pn);
int k = upper_bound(pnums, pnums + pn, 100000) - pnums;
//for (int i = k; i < pn; i++) printf("%d ", pnums[i]); putchar('\n');
int n;
scanf("%d", &n);
if (n == 1) {
puts("1");
return 0;
}
n--;
int m = 0;
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++)
as[m++] = (ll)pnums[k + i] * pnums[k + j];
sort(as, as + m);
printf("%lld\n", as[n - 1]);
return 0;
}
tnakao0123