結果

問題 No.1058 素敵な数
ユーザー risujirohrisujiroh
提出日時 2020-05-22 22:30:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 206,420 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 17:29:18
合計ジャッジ時間 2,703 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

vector<int> sieve(int n) {
  vector<bool> b(n / 3 + 1, true);
  vector<int> res{2, 3};
  for (int p = 5, d = 4; p * p <= n; p += d = 6 - d) if (b[p / 3])
    for (int i = p * p, di = p % 3 * 2 * p; i <= n; i += di = 6 * p - di)
      b[i / 3] = false;
  for (int p = 5, d = 4; p <= n; p += d = 6 - d) if(b[p / 3]) res.push_back(p);
  while (not res.empty() and res.back() > n) res.pop_back();
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  auto ps = sieve(2e5);
  int s = lower_bound(begin(ps), end(ps), (int)1e5) - begin(ps);
  vector<long long> v{1};
  for (int j = 0; j < 10; ++j) {
    for (int i = 0; i <= j; ++i) {
      v.push_back((long long)ps[s + i] * ps[s + j]);
    }
  }
  sort(begin(v), end(v));
  int n;
  cin >> n;
  --n;
  cout << v[n] << '\n';
}
0