結果

問題 No.3035 2018
ユーザー arg-53arg-53
提出日時 2018-05-27 22:48:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 146,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 19:44:46
合計ジャッジ時間 2,076 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int count(int n) {
  int v = sqrt(n);
  vector<int> smalls(v + 1);
  vector<int> larges(v + 1);
  for (int i = 1; i <= v; ++i) {
    smalls[i] = i - 1;
  }
  for (int i = 1; i <= v; ++i) {
    larges[i] = n / i - 1;
  }
  for (int p = 2; p <= v; ++p) {
    if (smalls[p] == smalls[p - 1]) {
      continue;
    }
    int q = p * p, c = smalls[p - 1];
    int w = v / p, e = min(v, n / q);
    for (int i = 1; i <= w; ++i) {
      larges[i] -= larges[i * p] - c;
    }
    for (int m = n / p, i = w + 1; i <= e; ++i) {
      larges[i] -= smalls[m / i] - c;
    }
    for (int i = v; i >= q; --i) {
      smalls[i] -= smalls[i / p] - c;
    }
  }

  int ret = smalls[(int)cbrt(n)];
  for (int p = 2; p <= v; ++p) {
    if (smalls[p] != smalls[p - 1]) {
      ret += larges[p] - smalls[p];
    }
  }
  return ret;
}

int main() {
  int n, lo = 0, hi = 1e9;

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

  return 0;
}

0