Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

### vicky1997's blog

By vicky1997, history, 2 years ago, ,

• Hi all !!! *

• Finding Prime Numbers In A Different Way... *

# include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

int isprime(ll n)

{

if(n<=3)

return 1;

if(n%2==0||n%3==0)

return 0;

for(ll i=5;i*i<=n;i+=6)

{

if(n%i==0||n%(i+2)==0)

return 0;

}

return 1;

}

int main()

{

//ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

ll N,i;

cout<<"\nEnter the Number N :";cin>>N;

cout<<"\nPrime Numbers <="<<N<<" are : \n";

for(i=2;i<=N;i++)

{

if(isprime(i))

{

cout<<i<<",";

}

}

return 0;


}

• Help Appreciated... *

•
• -8
•

 » 2 years ago, # |   0 Auto comment: topic has been updated by sirius_black (previous revision, new revision, compare).
 » 2 years ago, # |   0 Auto comment: topic has been updated by sirius_black (previous revision, new revision, compare).
 » 19 months ago, # | ← Rev. 2 →   0 #include #include using namespace std; int main() { int Size = 1e5+5; bool arr[Size]; arr[1] = true; for(int i = 2; i <= sqrt(1e5); i++) { if(arr[i] == false) for(int j = i*i; j <= 1e5; j+= i) arr[j] = true; } //if arr[i] == false then i is a prime number return 0; } 
•  » » 14 months ago, # ^ |   0 You only need to change the constant 1e5 to the variable N whose value is input from cin or stdin.
 » 19 months ago, # |   0 is it efficient to answer all the queries where query<=1e6??????
 » 14 months ago, # |   0 It is classic fast implementation of simple check ,you can check . It is a fast ,but not very fast . If you want very very fast ,you must write sieve of eratosthenes.My implementation of classic simple check . long long checkprost(ll cis) { if(cis==2 || cis==3)return 1; else if(cis==1 || cis%2==0 || cis%3==0)return 0; for(long long i=5,p=2;i*i<=cis;i+=p,p=6-p) { if(cis%i==0)return 0; } return 1; } If it is a simple ,it will return 1 ,else return 0 .