Advertisement
informaticage

Inefficient primes list in range

May 2nd, 2021
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. upper_bound = int(input("Upperbound: "))
  2.  
  3. for num in range(2, upper_bound + 1):
  4.     # Controlliamo se num รจ primo
  5.     divisors_amount = 0
  6.     for divisor in range(2, num):
  7.         if(num % divisor == 0):
  8.             # Se sono qui anche solo una volta allora non ho un numero primo
  9.             divisors_amount = divisors_amount + 1
  10.  
  11.     # Dopo aver controllato tutti i divisori
  12.     # Se ne ho trovati 0 allora ho un numero primo
  13.     if(divisors_amount > 0):
  14.         print(num)
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement