Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt
- import time
- nums = []
- s = 0
- n = 0
- m = 0
- lim = 0
- yorn = ''
- print("Enter a limit for this search: ", end="")
- lim = int(input())
- if lim == 0:
- lim = 100000000
- s = int(sqrt(lim))
- tStart = time.time()
- nums = [0 for i in range(lim + 1)]
- for n in range(2, s):
- if nums[n] == False:
- m = n * n
- while m <= lim:
- nums[m] = True
- m += n
- tStop = time.time()
- Elapsed = tStop - tStart
- print("It took ", (Elapsed % 60), " seconds to complete.")
- print("Do you want to list results (Y/N)? ", end="")
- yorn = input()
- m = 0
- for n in range(2, lim):
- if nums[n] == False:
- if yorn == 'y':
- print(n)
- m += 1
- print("")
- print("Total primes = ", m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement