結果

問題 No.1058 素敵な数
ユーザー optopt
提出日時 2020-05-22 21:34:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 3,061 bytes
コンパイル時間 2,719 ms
コンパイル使用メモリ 207,784 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 16:11:10
合計ジャッジ時間 3,299 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


struct Eratos {
  vector<int> primes, min_factor;
  vector<bool> isprime;
  Eratos(int MAX) : primes(),
                    isprime(MAX+1, true),
                    min_factor(MAX+1, -1) {
    isprime[0] = isprime[1] = false;
    min_factor[0] = 0, min_factor[1] = 1;
    for (int i = 2; i <= MAX; i++) {
      if (!isprime[i]) continue;
      primes.push_back(i);
      min_factor[i] = i;
      for (int j = i*2; j <= MAX; j += i) {
        isprime[j] = false;
        if (min_factor[j] == -1) min_factor[j] = i;
      }
    }
  }
  // prime factorization
  vector<pair<int,int>> factorize(int n) {
    vector<pair<int,int>> res;
    while (n != 1) {
      int prime = min_factor[n];
      int exp = 0;
      while (min_factor[n] == prime) {
        exp++;
        n /= prime;
      }
      res.push_back(make_pair(prime, exp));
    }
    return res;
  }
};

int main() {
  ll n; cin >> n;

  if (n == 1) {
    cout << 1 << "\n";
    return 0;
  }

  Eratos E(int(2e5));
  Vll p;
  rep2(i, 1e5, 2e5) {
    if (E.isprime[i]) p.push_back(i);
    if (p.size() == 10) break;
  }

  Vll q;
  rep(i, 10) rep(j, 10) {
    q.push_back(p[i] * p[j]);
  }
  sort(all(q));
  q.erase(unique(all(q)), q.end());

  ll ans = q[n-2];
  cout << ans << "\n";
  return 0;
}
0