結果

問題 No.3079 アルベド
ユーザー Ricky_ponRicky_pon
提出日時 2022-04-01 16:43:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 3,182 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 206,604 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 00:52:46
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 27 ms
5,376 KB
testcase_02 AC 18 ms
5,376 KB
testcase_03 AC 13 ms
5,376 KB
testcase_04 AC 21 ms
5,376 KB
testcase_05 AC 17 ms
5,376 KB
testcase_06 AC 20 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 15 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>


#include <algorithm>
#include <vector>

struct Sieve {
    std::vector<int> min_factor, prime;

    Sieve(int n) {
        min_factor.resize(n + 1, 0);
        for (int i = 2; i <= n; ++i) {
            if (min_factor[i] == 0) {
                min_factor[i] = i;
                prime.push_back(i);
            }
            for (int x : prime) {
                if (x * i > n || x > i) break;
                min_factor[x * i] = x;
            }
        }
    }

    std::vector<std::pair<int, int>> prime_factor(int n) {
        std::vector<std::pair<int, int>> res;
        while (n > 1) {
            if (res.empty() || res.rbegin()->first != min_factor[n]) {
                res.emplace_back(min_factor[n], 1);
            } else
                ++res.rbegin()->second;
            n /= min_factor[n];
        }
        return res;
    }

    void divisor_dfs(std::vector<std::pair<int, int>> &p, int t, int cur,
                     std::vector<int> &res) {
        if (cur == (int)p.size()) {
            res.push_back(t);
            return;
        }
        divisor_dfs(p, t, cur + 1, res);
        for (int _ = 0; _ < p[cur].second; ++_) {
            t *= p[cur].first;
            divisor_dfs(p, t, cur + 1, res);
        }
    }

    std::vector<int> get_divisor(int n, bool sorted = false) {
        std::vector<int> res;
        auto p = prime_factor(n);
        divisor_dfs(p, 1, 0, res);
        if (sorted) sort(res.begin(), res.end());
        return res;
    }
};


#include <algorithm>
#include <cassert>
#include <vector>

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}

template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct CoordComp {
    std::vector<T> v;
    bool sorted;

    CoordComp() : sorted(false) {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        std::sort(v.begin(), v.end());

        v.erase(std::unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }

    T &operator[](int i) { return v[i]; }
};


#define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second

using namespace std;

using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;

int main() {
    Sieve sv(100010);
    int t;
    scanf("%d", &t);
    rep(tt, t) {
        int n;
        scanf("%d", &n);
        printf("%ld\n", upper_bound(sv.prime.begin(), sv.prime.end(), n) -
                            sv.prime.begin());
    }
}
0