I was implementing Sieve's Algorithm for finding Prime Numbers up to n. I am unable to find out why is it running into infinite loop.
Here I'm giving the code snippet. Please help.
for(int j=2;j<=Math.sqrt(n);j++){
if(a[j]==true){
int x=0;
for(int p=(j*j+x*j); p<=n;x++){
a[p]=true;
}
}
}