Guest User

Increasing Primes

a guest
Sep 26th, 2020
390
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import operator
  2.  
  3. def prime_list(n):
  4.     sieve = [True] * n
  5.     for i in xrange(3, int(n ** 0.5) + 1, 2):
  6.         if sieve[i]:
  7.             sieve[i * i::2 * i]=[False]*((n - i * i - 1) / (2 * i) + 1)
  8.     return [2] + [i for i in xrange(3, n, 2) if sieve[i]]
  9.  
  10. biggest_prime = 982451653
  11. list_of_primes = prime_list(biggest_prime)
  12.  
  13. print('49,999,999 prime numbers generated...\n')
  14.  
  15. #-----------------------------------------------------------------------
  16.  
  17. last = 1
  18.  
  19. data = {}
  20.  
  21. for i, prime in enumerate(list_of_primes):
  22.     num = i + 1
  23.     percent_increase = ((prime / last) - 1) * 100
  24.  
  25.     data.update({prime : percent_increase})
  26.  
  27.     last = float(prime)
  28.  
  29. new = []
  30.  
  31. sorted_x = sorted(data.items(), key=operator.itemgetter(1))
  32.  
  33. for a, b in sorted_x:
  34.     new.append(str(a) + ', (' + str(b) + '%)')
  35.  
  36. new = new[::-1] # Reverse list
  37.  
  38. with open('/path/to/results', 'w') as the_file:
  39.     for item in new[:1000000]:
  40.         the_file.write(str(item) + '\n')
RAW Paste Data