結果

問題 No.3035 2018
ユーザー Min_25Min_25
提出日時 2018-04-05 19:49:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,899 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 85,384 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 17:50:32
合計ジャッジ時間 1,504 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstring>

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <stack>
#include <queue>

#include <tuple>
 
#define getchar getchar_unlocked
#define putchar putchar_unlocked
 
#define _rep(_1, _2, _3, _4, name, ...) name
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c))
#define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__)
 
using namespace std;
 
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f80 = long double;
 
int get_int() {
  int n, c, sign = 0;
  while ((c = getchar()) < '-');
  if (c == '-') sign = 1, n = 0;
  else n = c - '0';
  while ((c = getchar()) >= '0') n = n * 10 + c - '0';
  return sign ? -n : n;
}

int count(int N) {
  int v = sqrt(N);
  vector<int> smalls(v + 1), larges(v + 1);
  rep(i, 1, v + 1) smalls[i] = i - 1;
  rep(i, 1, v + 1) larges[i] = N / i - 1;
  rep(p, 2, v + 1) if (smalls[p] > smalls[p - 1]) {
    int q = p * p, e = min(v, N / q), c = smalls[p - 1];
    rep(i, 1, e + 1) larges[i] -= ((i * p <= v) ? larges[i * p] : smalls[N / (i * p)]) - c;
    for (int i = v; i >= q; --i) smalls[i] -= smalls[i / p] - c;
  }
  int ret = 0;
  rep(i, 2, v + 1) if (smalls[i] > smalls[i - 1]) {
    ret += larges[i] - smalls[i];
  }
  ret += smalls[int(cbrtl(N))];
  return ret;
}

void solve() {
  int N;
  while (~scanf("%d", &N)) {
    int lo = 1, hi = 5150000;
    while (hi - lo > 1) {
      int mi = (lo + hi) >> 1;
      if (count(mi) < N) lo = mi;
      else hi = mi;
    }
    printf("%d\n", hi);
  }
}

int main() {
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
0