compro_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub siro53/compro_library

:heavy_check_mark: エラトステネスの篩
(math/eratosthenes.hpp)

Verified with

Code

#pragma once

#include <vector>

class Eratosthenes {
  public:
    Eratosthenes() {}
    explicit Eratosthenes(int n) : n(n), isp(n + 1, true) {
        isp[0] = isp[1] = false;
        for(int i = 2; i * i <= n; i++) {
            if(!isp[i]) continue;
            for(int j = i * i; j <= n; j += i) isp[j] = false;
        }
    }
    bool operator[](int k) const { return isp[k]; }

  private:
    int n;
    std::vector<bool> isp;
};
#line 2 "math/eratosthenes.hpp"

#include <vector>

class Eratosthenes {
  public:
    Eratosthenes() {}
    explicit Eratosthenes(int n) : n(n), isp(n + 1, true) {
        isp[0] = isp[1] = false;
        for(int i = 2; i * i <= n; i++) {
            if(!isp[i]) continue;
            for(int j = i * i; j <= n; j += i) isp[j] = false;
        }
    }
    bool operator[](int k) const { return isp[k]; }

  private:
    int n;
    std::vector<bool> isp;
};
Back to top page