VvyLw's Library

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

View the Project on GitHub

:heavy_check_mark: Sieve of Eratosthenes
(C++/math/primetable.hpp)

Required by

Verified with

Code

#pragma once

#include <vector>
namespace Heileden {
struct p_table {
    std::vector<int> SoE;
    p_table(const int n): SoE(n + 1, 1) {
        SoE[0] = SoE[1] = 0;
        for(int64_t i = 2; i <= n; ++i) {
            if(!SoE[i]) {
                continue;
            }
            for(int64_t j = i * i; j <= n; j += i) {
                SoE[j] = 0;
            }
        }
    }
    std::vector<int> get() {
        std::vector<int> p;
        for(size_t i = 2; i < SoE.size(); ++i) {
            if(SoE[i]) {
                p.emplace_back(i);
            }
        }
        return p;
    }
};
}

/**
 * @brief Sieve of Eratosthenes
 */
#line 2 "C++/math/primetable.hpp"

#include <vector>
namespace Heileden {
struct p_table {
    std::vector<int> SoE;
    p_table(const int n): SoE(n + 1, 1) {
        SoE[0] = SoE[1] = 0;
        for(int64_t i = 2; i <= n; ++i) {
            if(!SoE[i]) {
                continue;
            }
            for(int64_t j = i * i; j <= n; j += i) {
                SoE[j] = 0;
            }
        }
    }
    std::vector<int> get() {
        std::vector<int> p;
        for(size_t i = 2; i < SoE.size(); ++i) {
            if(SoE[i]) {
                p.emplace_back(i);
            }
        }
        return p;
    }
};
}

/**
 * @brief Sieve of Eratosthenes
 */
Back to top page