I just used Sieve of erathosthenes algorithm, at beginning with single int passing value, it was working just fine, but further, loop won't execute at all. Please help .. this is the problem where the following code belongs. http://ift.tt/1MVUNPA
include
include
void sieve_algo(long in, long fi){
bool prime_initial[in], prime[fi+1];
memset(prime, true, sizeof(prime));
memset(prime, false, sizeof(prime_initial));
for(long i=in; i*i<=fi; i++ ){ // this loop is not executing
if(prime[i] == true){
for(long p=i*2; p<=fi; p+=i)
prime[p]= false;
}
}
for(long k=in; k<=fi; k++){
if(prime[k]==true){
printf("%ld\n", k);
}
}
}
int main(){
int tc;
scanf("%d", &tc);
for(int i=0; i<tc; i++){
long int m,n;
scanf("%ld %ld", &m, &n);
sieve_algo(m,n);
printf("\n");
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire