Problem 46 : Goldbach's other conjecture

Problem Statement

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 + 2×12
15 = 7 + 2×22
21 = 3 + 2×32
25 = 7 + 2×32
27 = 19 + 2×22
33 = 31 + 2×12 \

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?

Solution

from math import sqrt

def isprime(x):
    if x%2==0:
        return False
    else:
        for i in range(3, int(x**0.5+1),2):
            if x % i == 0:
                return False
        return True

number=3
prime=[2]

flag=True

while flag:
    if isprime(number): prime.append(number)
    else:
        for i in prime:
            if sqrt(((number-i)/2)) == int(sqrt(((number-i)/2))):
                break
        else:
            print(number)
            break
    number=number+2

Output

5777