This is a prime number screening most simplest way
The core idea is to use factor, a 0-1 mark
#define maxn 1000000
int prime[maxn + 5] = {1, 1, 0};
void init(){
for(int i = 1; i <= maxn ; i++){
if(prime[i]) continue;
for(int j = 2 * i; j <= maxn; j += i){
prime[j] = 1;
}
}