Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import numpy as np
- import math
- def is_prime(num):
- if num < 2:
- return False
- for i in range(2, int(num**0.5) + 1):
- if num % i == 0:
- return False
- return True
- def generate_primes(to_x):
- prime_numbers = [ 2 ]
- x = 0
- while x < to_x:
- x += 1
- # First Law: A number, of square root, whose floor is equal to the square root,
- # being then an integer itself, must not be a prime.
- #
- # Second Law: The number may not be equal in a MOD of any previous prime.
- if ((x % 2 == 0) or (math.sqrt(x)) == math.floor(math.sqrt(x)) ):
- continue
- y = 1
- for i in prime_numbers:
- if (i != x) and (x % i == 0): # highly improved
- y = 0
- break
- if (y != 0):
- prime_numbers.append(x)
- x += 1
- return (prime_numbers)
- # Example usage:
- start_x = 2
- prime_numbers0 = generate_primes(1000)
- g = 0
- olist = []
- for i in prime_numbers0:
- if is_prime(i):
- g += 1;
- else:
- olist.append(i)
- print(f"{g} {len(prime_numbers0)} {len(olist)}")
- print(prime_numbers0)
- print(olist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement