forked from bashmohandes/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem_46.py
43 lines (33 loc) · 888 Bytes
/
Problem_46.py
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
#! /usr/bin/env python
from math import sqrt
from AutoMeasure import AutoMeasure
from utils import is_prime, is_even, is_square
__author__ = 'Mohamed.Elsherif'
cache = {}
def is_prime_c(n):
if n in cache:
return cache[n]
cache[n] = is_prime(n)
return cache[n]
@AutoMeasure
def main():
current_odd = 9
while True:
if not is_prime_c(current_odd) and not conjecture_correct(current_odd):
print current_odd
return
current_odd += 2
def conjecture_correct(current_odd):
for i in xrange(1, current_odd - 1):
if not is_prime_c(i):
continue
r = current_odd - i
if not is_even(r):
continue
r /= 2
if is_square(r):
#print "%d = %d + 2 * %d" % (current_odd, i, r)
return True
return False
if __name__ == "__main__":
main()