Advertisement
onexiv

Riemann official code

Jan 26th, 2024
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. # import numpy as np
  2. import math
  3.  
  4. def is_prime(num):
  5.     if num < 2:
  6.         return False
  7.     for i in range(2, int(num**0.5) + 1):
  8.         if num % i == 0:
  9.             return False
  10.     return True
  11.  
  12. def generate_primes(to_x):
  13.     prime_numbers = [ 2 ]
  14.     x = 0
  15.     while x < to_x:
  16.         x += 1
  17.         # First Law: A number, of square root, whose floor is equal to the square root,
  18.         # being then an integer itself, must not be a prime.
  19.         #
  20.         # Second Law: The number may not be equal in a MOD of any previous prime.
  21.         if ((x % 2 == 0) or (math.sqrt(x)) == math.floor(math.sqrt(x)) ):
  22.             continue
  23.         y = 1
  24.         for i in prime_numbers:
  25.             if (i != x) and (x % i == 0): # highly improved
  26.                 y = 0
  27.                 break
  28.         if (y != 0):
  29.             prime_numbers.append(x)
  30.             x += 1
  31.     return  (prime_numbers)
  32.  
  33. # Example usage:
  34. start_x = 2
  35. prime_numbers0 = generate_primes(1000)
  36. g = 0
  37. olist = []
  38. for i in prime_numbers0:
  39.     if is_prime(i):
  40.         g += 1;
  41.     else:
  42.         olist.append(i)
  43.  
  44. print(f"{g} {len(prime_numbers0)} {len(olist)}")
  45. print(prime_numbers0)
  46. print(olist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement