-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path46.py
More file actions
41 lines (28 loc) · 833 Bytes
/
46.py
File metadata and controls
41 lines (28 loc) · 833 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
#!/usr/bin/env python3
# Finds the smallest odd composite that violates Goldbach's other conjecture.
"""Project Euler Problem 46: https://projecteuler.net/problem=46"""
from itertools import permutations
num = "7654321"
def is_perfect_square(n):
"""Return True if n is a perfect square."""
return (n**0.5).is_integer()
def solve():
"""Find the smallest odd composite that violates Goldbach's other conjecture."""
import sympy
i = 1
num = 5
while True:
num += 2
i = num - 2
flag = False
if sympy.isprime(num):
continue
while i > 0:
if sympy.isprime(i) and is_perfect_square((num - i) / 2):
flag = True
break
i -= 2
if not flag:
print(num)
break
solve()