結果

問題 No.1058 素敵な数
ユーザー KensKens
提出日時 2020-05-22 21:31:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 175,116 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 15:58:12
合計ジャッジ時間 2,495 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX =2e5;

class Prime {
  vector<bool> is_prime;
  int n;
public:
  Prime(int n) : n(n) {
    is_prime.resize(n+1,true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++){
      if(is_prime[i]){
        for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
      }
    }
  }
  bool operator[](const int &k) const {
    return is_prime[k];
  }
};

int main(){
  int n;
  cin >> n;
  Prime p(MAX);
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }
  n--;
  vector<ll> v;
  ll k = 1e5+1;
  while(v.size() < n+1) {
    if(p[k]) v.push_back(k);
    k++;
  }
  vector<ll> a;
  rep(i,v.size()) {
    for(int j = i; j < v.size(); j++) a.push_back(v[i]*v[j]);
  }
  sort(a.begin(),a.end());
  cout << a[n-1] << endl;
  return 0;
}
0