結果

問題 No.1058 素敵な数
ユーザー polyesterpolyester
提出日時 2020-05-23 00:05:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,419 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 97,904 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 19:45:48
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
vector<bool> IsPrime;
void sieve(ll max) {
  if(max + 1 > IsPrime.size()) {   // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for(ll i = 2; i * i <= max; ++i) {     // 0からsqrt(max)まで調べる
    if(IsPrime[i]) {                     // iが素数ならば
      for(ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は
        IsPrime[i * j] = false;          // 素数ではない
      }
    }
  }
}

int main() {
  ll n;
  cin >> n;
  if(n == 1) {
    cout << 1 << endl;
  } else {
    int cnt = 0;
    vector<ll> ans;
    int a = 100000;
    sieve(1000000);
    while(cnt <= 10) {
      if(IsPrime[a]) {
        cnt++;
        ans.push_back(a);
      }
      a++;
    }
    map<ll, ll> mp;
    for(int i = 0; i < 10; i++) {
      for(int j = 0; j < 10; j++) {
        mp[ans[i] * ans[j]]++;
      }
    }
    cnt = 0;
    for(auto p : mp) {
      cnt++;
      if(n - 1 == cnt) {
        cout << p.first << endl;
        return 0;
      }
    }
  }
  return 0;
}
0