A prime number is a number that is divisible only by itself, for example the first few prime numbers are 2,3,5,7,11,13,17,..... The straightforward way to find all prime numbers is to iterate through the numbers and see each number meets a specific criterion. The program does this by, Check if the number ends with a 2,4,5,6,8 or a 0. If this is the case it's not prime. Check if the number is divisible by 3 or 7, then it's not prime These 2 conditions alone doesn't suffice. For example take the number 1079, this is divisible by 13, so we have to check if each number can be divided by any other prime numbers which are lower than the number itself. But there's a shortcut. We don't have to check with every prime number lower than the number. Take the prime number 37. We take it's square root rounded down, which is 6. Then we check the prime numbers only upto 7 because otherwise we do unnecessary checks, e.g. we can check 2*6. 3*6, 5*6 but as soon as we go 7*6 ...
Programming, Machine Learning and Capital Markets