competitive_library

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

View the Project on GitHub knshnb/competitive_library

:heavy_check_mark: test/yosupo/enumerate_primes.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_primes"

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr  5 19:29:53 JST 2020
 **/

#define CALL_FROM_TEST
#include "../../src/Math/Eratosthenes.hpp"
#undef CALL_FROM_TEST

signed main() {
    Int n, A, B;
    std::cin >> n >> A >> B;
    Eratosthenes er(n + 1);
    Int num = ((Int)er.primes.size() - B + A - 1) / A;
    std::cout << er.primes.size() << " " << num << std::endl;
    REP(i, num) {
        std::cout << er.primes[A * i + B] << " ";
    }
    std::cout << std::endl;
}
#line 1 "test/yosupo/enumerate_primes.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_primes"

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr  5 19:29:53 JST 2020
 **/

#define CALL_FROM_TEST
#line 1 "src/Math/Eratosthenes.hpp"
/// @docs src/Math/Eratosthenes.md
struct Eratosthenes {
    std::vector<bool> is_prime;
    std::vector<int> primes;
    Eratosthenes(int n) {
        is_prime.assign(n, true);
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i < n; i++) {
            if (!is_prime[i]) continue;
            for (int j = i * 2; j < n; j += i) {
                is_prime[j] = false;
            }
        }
        for (int i = 2; i < n; i++) {
            if (is_prime[i]) primes.push_back(i);
        }
    }
};
#line 19 "test/yosupo/enumerate_primes.test.cpp"
#undef CALL_FROM_TEST

signed main() {
    Int n, A, B;
    std::cin >> n >> A >> B;
    Eratosthenes er(n + 1);
    Int num = ((Int)er.primes.size() - B + A - 1) / A;
    std::cout << er.primes.size() << " " << num << std::endl;
    REP(i, num) {
        std::cout << er.primes[A * i + B] << " ";
    }
    std::cout << std::endl;
}
Back to top page