find prime numbers in a given range for big input python 1

find prime numbers in a given range for big input python

import math
print 2
for num in range(3,101,2):
    if all(num%i!=0 for i in range(3,int(math.sqrt(num))+1, 2)):
        print (num)

Here is what the above code is Doing:
1. It’s printing 2 as the first prime number.
2. Then it’s iterating over all the odd numbers from 3 to 100.
3. For each number, it’s checking if it’s divisible by any odd number from 3 to sqrt(num).
4. If it’s not divisible by any of these numbers, then it’s a prime number.

Similar Posts