blob: 91509d2ce1a4cb2fe0e3f734d4d4c398b54d1b7d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/usr/bin/python3
# Challenge 012
#
# Challenge #1
# The numbers formed by adding one to the products of the smallest primes are
# called the Euclid Numbers (see wiki). Write a script that finds the smallest
# Euclid Number that is not prime. This challenge was proposed by
# Laurent Rosenfeld.
import sys
from primePy import primes
def next_prime(n):
if n <= 1:
return 2
else:
n += 1
while not primes.check(n):
n += 1
return n
def euclid_iter():
prime = 1
prime_prod = 1
while True:
prime = next_prime(prime)
prime_prod *= prime
yield prime_prod+1
for n in euclid_iter():
if primes.check(n):
pass
else:
print(n)
break
|