結果

問題 No.3079 アルベド
ユーザー furafura
提出日時 2023-09-13 03:12:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 3,512 ms
コンパイル使用メモリ 247,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 03:12:52
合計ジャッジ時間 5,287 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

class Eratosthenes_sieve {
    vector<bool> er;
    vector<int> p;

  public:
    Eratosthenes_sieve(int n): er(n + 1, true) {
        if (n >= 0) er[0] = false;
        if (n >= 1) er[1] = false;
        for (int i = 2; i * i <= n; i++)
            if (er[i])
                for (int j = i * i; j <= n; j += i) er[j] = false;
        rep (i, n + 1)
            if (er[i]) p.emplace_back(i);
    }

    vector<int> primes() const {
        return p;
    }

    bool is_prime(int a) const {
        assert(a <= (int)er.size() - 1);
        return a >= 0 && er[a];
    }
};

int main() {
    auto P = Eratosthenes_sieve(1e5).primes();

    int t;
    cin >> t;
    rep (_, t) {
        int n;
        cin >> n;
        cout << upper_bound(begin(P), end(P), n) - begin(P) << "\n";
    }

    return 0;
}
0