# IIS-L-27120 (MO 437635): is every prime q >= 7 of the form x^2 + p*y^2 with p prime, p < q?
# Sieve to N; for each prime q, try y = 1 (q - x^2 prime), then y >= 2. Prints all q with no y=1 rep and all q with no rep at all.
import sys, numpy as np, numba as nb, time
N = int(float(sys.argv[1])) if len(sys.argv) > 1 else 10**9
t0 = time.time()
s = np.ones(N + 1, dtype=np.bool_); s[:2] = False
for i in range(2, int(N**0.5) + 1):
    if s[i]: s[i*i::i] = False
@nb.njit(cache=True)
def scan(s, N):
    no_y1 = []; none = []
    for q in range(3, N + 1, 2):
        if not s[q]: continue
        found = False
        x = 0
        while x * x < q:
            r = q - x * x
            if r < q and s[r]:
                found = True; break
            x += 1
        if found: continue
        no_y1.append(q)
        y = 2
        while y * y * 2 <= q and not found:
            x = 0
            while x * x < q:
                r = q - x * x
                if r % (y * y) == 0 and s[r // (y * y)] and r // (y * y) < q:
                    found = True; break
                x += 1
            y += 1
        if not found: none.append(q)
    return no_y1, none
a, b = scan(s, N)
print("N =", N, "primes:", int(s.sum()), "time %.0fs" % (time.time() - t0))
print("primes q with no rep q = x^2 + p (p<q prime):", len(a), a)
print("primes q with no rep q = x^2 + p y^2 at all:", b)
