informaticage

Semi efficient primality test in range python

May 2nd, 2021
582
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. upper_bound = int(input("Upperbound: "))
  3.  
  4. primes = []
  5. for num in range(2, upper_bound + 1):
  6.     # Controlliamo se num è primo
  7.     is_prime = True
  8.     for divisor in range(2, int(math.sqrt(num)) + 1):
  9.         if(num % divisor == 0):
  10.             # Se sono qui anche solo una volta allora non ho un numero primo
  11.             is_prime = False
  12.             break
  13.     if(is_prime):
  14.         primes.append(num)
  15.  
  16. print(primes)
  17.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×