You can try the code using the following link:
Code
For further actions, you may consider blocking this person and/or reporting abuse
You can try the code using the following link:
Code
For further actions, you may consider blocking this person and/or reporting abuse
Trix Cyrus -
Dmitry Koleev -
MyExamCloud -
Milcah03 -
Top comments (8)
this doesn't work for all numbers
tested with 1111111 & 121111
[EDIT1]replace the loop by
[EDIT2] to explain : the
return true
in the for loop will always return true on the first try, and the&&
in the if need to be a||
to test if it works, take high odd number, and if you wanna be sure, add
printf("%d %% %d = %d | ", n, i, n%i);
andprintf("%d %% %d = %d | ", n, i+2, n%(i+2));
in the for loop (that's a fastest way instead of debug)Hey thank you so much for the correction!
It's
i + 6
noti + 4
, the only issue was the return inside the for loop.And
n == 2 || n == 3
can be simplified asn < 4
orn <=3
the only thing is that
i+4
will check all odd number, even those divided by 3, where thei+6
won't check the5+6*i
numberI admit it's not usefull, because all
(5+6*i)+4
numbers can be divided by 3In JS, using regex:
that's evil, I love it 😍
Would you like to explain it?
I didn't write it, but it's fascinating... noulakaz.net/2007/03/18/a-regular-...