Checking For Prime

Checking For Prime

prime numbers are surprisingly easy to check for. to check if a number is prime, we divide it by it’s factors. 1 is not prime

we take all numbers from 2 to the num and we start dividing by 2, 3, 4, 5, …

but really we need only to go to half the numbers, upto n//2 + 1

then we can use it like that:

for primes upto 100. pretty easy.

checking for the first time there is a difference of 100

the above checks the first time there is a difference of 100. modify the loop to check for the next 10 occurances.

  •  
  •  
  •  
  •  
  •  
  •  

Lives in Mauritius, cruising python waters for now.