結果

問題 No.3079 アルベド
ユーザー hanyuhanyu
提出日時 2021-04-01 23:22:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 202,708 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 06:49:00
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using ll = long long;

// エラトステネスの篩(nは1以上, 素数列挙のみならi*i<=nで良い) O(nloglogn)
vector<bool> sieve(int n) {
  vector<bool> x(n + 1, true);
  x.at(0) = x.at(1) = false;
  for (int i = 2; i <= n; i++) {
    if (x.at(i)) {
      for (int j = 2 * i; j <= n; j += i) x.at(j) = false;
    }
  }
  return x;
}

int main() {
  int t;
  cin >> t;
  
  auto s = sieve(101000);
  vector<int> x(101000);
  for (int i = 2; i < 101000; i++) {
    if (s[i]) x[i] = 1;
    x[i] += x[i - 1];
  }
  
  while (t--) {
    int n;
    cin >> n;
    cout << x[n] << '\n';
  }
}
0