Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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(start_x):
- prime_numbers = []
- x = start_x
- while x < 100000:
- if x % 2 == 0:
- x += 1
- continue
- elif math.sqrt(x) == math.floor(math.sqrt(x)+0.49):
- x += 1
- continue
- elif x % 7 == 0:
- x += 1
- continue
- elif x % 5 == 0:
- x += 1
- continue
- elif x % 3 == 0:
- x += 1
- continue
- # if (y + 2 <= x):
- prime_numbers.append(x)
- for i in prime_numbers:
- if i != x and x % i == 0:
- prime_numbers.remove(x)
- break
- x = x + 1
- return prime_numbers
- # Example usage:
- start_x = 3
- prime_numbers0 = generate_primes(start_x)
- print(" ", len(prime_numbers0))
- # print(f"{prime_numbers0}")
- g = 0
- glist = []
- for i in prime_numbers0:
- if is_prime(i):
- g += 1;
- else:
- glist.append(i)
- print(f"{glist}/{len(prime_numbers0)}")
- start_x = 5
- prime_numbers1 = []
- prime_numbers1 = generate_primes(start_x)
- print(" ", len(prime_numbers1))
- g = 0
- for i in prime_numbers1:
- if is_prime(i):
- g += 1;
- print(f"{g}/{len(prime_numbers1)}")
- print(prime_numbers0 == prime_numbers1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement