[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); and printf("%d %% %d = %d | ", n, i+2, n%(i+2)); in the for loop (that's a fastest way instead of debug)
the only thing is that i+4 will check all odd number, even those divided by 3, where the i+6 won't check the 5+6*i number
I admit it's not usefull, because all (5+6*i)+4 numbers can be divided by 3
this doesn't work for all numbers
tested with 1111111 & 121111
[EDIT1]replace the loop by
[EDIT2] to explain : the
return truein 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)It's
i + 6noti + 4, the only issue was the return inside the for loop.And
n == 2 || n == 3can be simplified asn < 4orn <=3the only thing is that
i+4will check all odd number, even those divided by 3, where thei+6won't check the5+6*inumberI admit it's not usefull, because all
(5+6*i)+4numbers can be divided by 3Hey thank you so much for the correction!