@@ -0,0 +1,1018 @@
+'''%0AIt was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.%0A%0A9 = 7 + 2%C3%971%5E2%0A15 = 7 + 2%C3%972%5E2%0A21 = 3 + 2%C3%973%5E2%0A25 = 7 + 2%C3%973%5E2%0A27 = 19 + 2%C3%972%5E2%0A33 = 31 + 2%C3%971%5E2%0A%0AIt turns out that the conjecture was false.%0A%0AWhat is the smallest odd composite that cannot be written as the sum of a prime and twice a square?%0A'''%0Afrom itertools import count%0A%0Adef composite_odds():%0A    for i in count(9,2):%0A        if next((n for n in range(3,int(i**.5)+1) if i%25n==0), None):%0A            yield i%0A%0Adef twice_a_squares(less_than):%0A    for i in count(1):%0A        square2 = i**2 * 2%0A        if square2 %3C less_than:%0A            yield square2%0A        else:%0A            break%0A%0Adef is_prime(n):%0A    divisor = next((i for i in range(2, int(n**.5)+1) if n%25i == 0), None)%0A    return divisor is None%0A%0Adef solve_p046():%0A    try:%0A        for co in composite_odds():%0A            next(ts for ts in twice_a_squares(less_than=co) if is_prime(co-ts))%0A    except StopIteration:%0A        return co%0A

Solve p046