-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp046.py
More file actions
executable file
·45 lines (38 loc) · 1012 Bytes
/
p046.py
File metadata and controls
executable file
·45 lines (38 loc) · 1012 Bytes
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
37
38
39
40
41
42
43
44
#It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.
#
#9 = 7 + 2x1^2
#15 = 7 + 2x2^2
#21 = 3 + 2x3^2
#25 = 7 + 2x3^2
#27 = 19 + 2x2^2
#33 = 31 + 2x1^2
#
#It turns out that the conjecture was false.
#
#What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
import logging
from prime import PrimeNumberPool
squares = [1, 4, 9]
def Check(n, prime):
if prime.IsPrime(n):
return 0
while (squares[-1] < n//2):
squares.append(len(squares)*len(squares))
for sq in squares:
if (sq*2 >= n):
return 0
if (prime.IsPrime(n-sq*2)):
return 1
def main(args):
prime = PrimeNumberPool()
n = 33
done = 0
while (done == 0):
if (prime.IsPrime(n)):
n += 2
continue
if (Check(n, prime) == 0):
logging.info(n)
done = 1
else:
n += 2