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 :: powers of 2 in cpp |
Cpp :: c++ ascii value |
Cpp :: passing a 2d array cpp |
Cpp :: Casino Number Guessing Game - C++ |
Cpp :: how to pass arrays by reference c++ |
Cpp :: random c++ |
Cpp :: type casting in cpp |
Cpp :: binpow in fenwick tree |
Cpp :: c++ split string by sstream |
Cpp :: declare a variable in cpp |
Cpp :: c++ define constant |
Cpp :: how to make sound in c++ |
Cpp :: run with cpp version |
Cpp :: c++ forloop |
Cpp :: qregexpvalidator qlineedit email address |
C :: find string in all files powershell |
C :: full installation of clang in ubuntu |
C :: how to make a hello world program in c |
C :: check if string starts with c |
C :: dvlprroshan |
C :: size of an array c |
C :: add 2 numbers in c |
C :: c program |
C :: how to sleep in c |
C :: addition in c |
C :: sum average min max in c array |
C :: convert int to string c |
C :: c get current month, year, day |
C :: warning: function returns address of local variable [-Wreturn-local-addr] |
C :: bootstrap form |