luckYrat's library.

This documentation is automatically generated by competitive-verifier/competitive-verifier


:heavy_check_mark: cpp/z_test/yosupo-enumerate_primes.cpp

Depends on

Required by

Code

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

#include "../../cpp/template/template.cpp"

#include "../../cpp/math/sieve-of-eratosthenes.cpp"


int main(){
  int n,a,b;cin>>n>>a>>b;
  SieveEratos P(n);
  cout << P.primes.size() << " " << (P.primes.size()-b+a-1)/a << endl;
  for(int i = b; P.primes.size() > i; i+=a){
    if(i != b)cout << " ";
    cout << P.primes[i];
  }
  cout << endl;
  return 0;
}
#line 1 "cpp/z_test/yosupo-enumerate_primes.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_primes"

#line 2 "cpp/template/template.cpp"

//yukicoder@cpp17

#include <iostream>
#include <iomanip>

#include <algorithm>

#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <random>

#include <bitset>

#include <complex>

#include <utility>

#include <numeric>

#include <functional>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;


const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
*/
#line 4 "cpp/z_test/yosupo-enumerate_primes.cpp"

#line 1 "cpp/math/sieve-of-eratosthenes.cpp"
struct SieveEratos{
  int N;
  vector<int> minp;
  vector<bool> t;
  vector<int> primes;
  map<int,int> invprimes;
  SieveEratos(){}
  SieveEratos(int n):N(n+1){
    generate();
  }
  void set(int n){
    N = n+1;
    generate();
  }
  void generate(){
    t.assign(N, true);
    t[0] = t[1] = false;
    for(int i = 2; N > i; i++){
      if(t[i]){
        primes.emplace_back(i);
        for(int j = i+i; N > j; j+=i){
          t[j] = false;
        }
      }
    } 
  }
  void generate_invprime(){
    for(size_t i = 0; primes.size() > i; i++){
      invprimes[primes[i]] = i+1;
    }

  }
  void generate_minfactor(){
    minp.assign(N, N+2);
    minp[0] = minp[1] = -1;
    for(int i = 2; N > i; i++){
      if(minp[i] == N+2){
        minp[i] = i;
        for(int j = i+i; N > j; j+=i){
          minp[j] = min(i, minp[j]);
        }
      }
    }
  }
  bool operator[](int x){return t[x] == x;}
};
#line 6 "cpp/z_test/yosupo-enumerate_primes.cpp"


int main(){
  int n,a,b;cin>>n>>a>>b;
  SieveEratos P(n);
  cout << P.primes.size() << " " << (P.primes.size()-b+a-1)/a << endl;
  for(int i = b; P.primes.size() > i; i+=a){
    if(i != b)cout << " ";
    cout << P.primes[i];
  }
  cout << endl;
  return 0;
}

Test cases

Env Name Status Elapsed Memory
g++ 1_00 :heavy_check_mark: AC 6 ms 3 MB
g++ 2_00 :heavy_check_mark: AC 6 ms 3 MB
g++ 499477801_00 :heavy_check_mark: AC 6837 ms 197 MB
g++ 499999993_00 :heavy_check_mark: AC 6716 ms 196 MB
g++ example_00 :heavy_check_mark: AC 7 ms 3 MB
g++ max_00 :heavy_check_mark: AC 6929 ms 196 MB
g++ max_01 :heavy_check_mark: AC 6868 ms 196 MB
g++ ten_00 :heavy_check_mark: AC 812 ms 49 MB
g++ ten_01 :heavy_check_mark: AC 127 ms 10 MB
g++ ten_02 :heavy_check_mark: AC 18 ms 4 MB
Back to top page