#include<iostream>
using namespace std;
bool isPrimrNumber(int number){
bool isPrimeFlag=true;
for(int i=2;i<number;i++){
if(number%i==0){
isPrimeFlag=false;
break;
}
}
return isPrimeFlag;
}
int main()
{
int number;
cout<<"Please enter your number";
cin>>number;
bool isPrimeFlag=isPrimeNumber(number)
if(isPrimeFlag)
{
cout<<"prime Number";
}
else
{
cout<<"not prime number";
}
}
#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 <math.h>
// time: O(sqrt(n)) .. space: O(1)
bool isPrime(int n) {
if (n < 2) return false;
int iter = 2;
while(iter <= sqrt(n)) {
if (n % iter == 0) return false;
iter++;
}
return true;
}