0
Help me understand this algorithim
So, all i'm trying to do is find a prime number. I've found this one algorithm to help me do so, problem is, i don't understand why it is doing what it is. here's the link to the code i replicated on my profile: https://code.sololearn.com/cVIZ9u5P9HF1 What is going on, and why?
2 Respostas
+ 2
*you pass a number as value
*value is divided by all numbers between 2 and value/2
*if any point value gets fully divided by any number it returns 0 otherwise loop continues and returns 1 when the loop ends
+ 2
A prime number is only dividable by itselfs and one, so it cant devide it by a higher number than a half of its value(17 % 13 != 0).
It also cant be a an even number, because they are devidable by two, thats because the for loop goes in 2 steps.
By the other numbers the programm just check, if the number is dividable by any uneven number that is lower than the half of the number.