int n;
vector<bool> is_prime(n+1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i] && (long long)i * i <= n) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#define N 1000000 //N is the Range (0..N)
bitset < N+1 > numbers;
vector < int > primes;
void sieve(){
numbers.set();
numbers[1] = 0;
for (int i = 2; i < N; i++){
if (numbers[i] == 1){
cout<<i<<endl;
primes.push_back(i);
for (int j = i*i; j<=N; j+=i)
numbers[j] = 0;
}
}
}
#include <cmath>
#include <vector>
using namespace std;
int n;
vector<int> ans;
vector<bool> is_prime(n+1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= sqrt(n); i++) {
if (is_prime[i]) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
for(int i=2;i<is_prime.size();i++){
if(is_prime[i]){
ans.push_back(i);
}
}
int n;
vector<char> is_prime(n+1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i] && (long long)i * i <= n) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
Code Example |
---|
Cpp :: how to make a typing effect c++ |
Cpp :: segmented sieve cpp |
Cpp :: c++ get environment variable |
Cpp :: how to do sets in cpp |
Cpp :: decltype in c++ |
Cpp :: convert string to lpstr |
Cpp :: c++ first letter of string |
Cpp :: double to int c++ |
Cpp :: string in cpp |
Cpp :: string to int c++ |
Cpp :: how to send email in c++ program |
Cpp :: sort 0 1 2 leetcode |
Cpp :: matrix in vector c++ |
Cpp :: stoi cpp |
Cpp :: console colors in C++ |
Cpp :: convert unsigned long to string c++ |
Cpp :: is power of 2 |
Cpp :: continue statement in c++ program |
Cpp :: find second highest number in c++ |
Cpp :: comparator in sort c++ |
Cpp :: print duplicate characters from string in c++ |
Cpp :: how to write hello world in c++ |
Cpp :: integer range in c++ |
Cpp :: sum of row s2 d array c++ |
Cpp :: convert int to string in c++ |
Cpp :: what is meant by pragma once in c++ |
Cpp :: c++ saying hello world |
Cpp :: factorial in c++ using recursion |
Cpp :: insert element in array c++ |
Cpp :: how to write a template c++ |