rcpl

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

View the Project on GitHub ruthen71/rcpl

:heavy_check_mark: math/prime_table.hpp

Required by

Verified with

Code

#pragma once

std::vector<bool> prime_table(int n) {
    std::vector<bool> res(n + 1, true);
    if (n >= 0) res[0] = false;
    if (n >= 1) res[1] = false;
    for (int p = 2; p * p <= n; p++) {
        if (!res[p]) continue;
        for (int i = p * p; i <= n; i += p) {
            res[i] = false;
        }
    }
    return res;
}
#line 2 "math/prime_table.hpp"

std::vector<bool> prime_table(int n) {
    std::vector<bool> res(n + 1, true);
    if (n >= 0) res[0] = false;
    if (n >= 1) res[1] = false;
    for (int p = 2; p * p <= n; p++) {
        if (!res[p]) continue;
        for (int i = p * p; i <= n; i += p) {
            res[i] = false;
        }
    }
    return res;
}
Back to top page