0
I need to find pairs of primes, the distance between which is two. why does the program stop working for numbers greater than 19
4 Respostas
+ 1
for (d=2; d <= Math.sqrt(b); d++){
if (b%d==0) //when d=2 never running thus if
{k=1;
break;
}
for (d=2; d <= Math.sqrt(b+2); d++){
if ((b+2)%d==0)
{l=1;
break;
}}
//after this loop d = 3 ,runn8ng for d=2,3 repeatedly
//and going back to above loop..
//d=4 <Math.sqrt(b) is true and again 2nd loop repeating f9r d=2,3 so infinite looping here..
+ 1
the variable i never got value 6, so server stops executing of this code
while (i < (a-1)) { // i 0..6
i=5, b=19, sqb=4.358898943540674, d=2
i=5, b=19, sqb=4.358898943540674, d=4
i=5, b=19, sqb=4.358898943540674, d=4
i=5, b=19, sqb=4.358898943540674, d=4
0
It says why, you just have to scroll down in output. It times out. That is a limitation of sololearn.
As an advice you should indent your code properly and follow basic guidelines. Makes it easier to read for everybody, including yourself
0
i tried to run it in other program on pc and it just stops on 19 without any notiffications