"""Independent pure-Python check of the counterexample to Jaffe Conj. 7.3 (arXiv 2610.17267):
a = 770, b = 3, c(a,b) = 9, g(770,9)/g(770,3) = 82110/13090 > 5.
Upper limits come from jaffe_exact.limit (proof in its docstring)."""
from math import gcd
from jaffe_exact import limit

def expressible(N, a, b):
    for y in range(N // b + 1):          # loop over y instead of x (different from jaffe_g)
        r = N - b*y
        if r % a == 0 and gcd(r // a, y) == 1:
            return True
    return False

a, b = 770, 3
c = next(k for k in range(b+1, 10**6) if gcd(k, a) == 1)
assert c == 9
for B, G in [(3, 13090), (9, 82110)]:
    assert not expressible(G, a, B)
    L = limit(a, B)
    bad = [N for N in range(G+1, L+1) if not expressible(N, a, B)]
    assert not bad, bad[:5]
    print(f"g({a},{B}) = {G}: {G} is not expressible and every N in ({G}, {L}] is")
print("ratio g(770,9)/g(770,3) =", 82110/13090, "> 5")
sols = [(x, (82110 - 770*x)//9) for x in range(82110//770 + 1) if (82110 - 770*x) % 9 == 0]
print("all solutions of 770x + 9y = 82110:", [(x, y, gcd(x, y)) for x, y in sols])
sols = [(x, (13090 - 770*x)//3) for x in range(13090//770 + 1) if (13090 - 770*x) % 3 == 0]
print("all solutions of 770x + 3y = 13090:", [(x, y, gcd(x, y)) for x, y in sols])
