"""Reconstruct and certify the finite prefix used in the proof for A387759. Run with Python 3.8+ and the standard library. No sequence data are required. """ from functools import lru_cache from hashlib import sha256 from math import gcd @lru_cache(None) def prime_divisors(n): factors = [] d = 2 while d * d <= n: if n % d == 0: factors.append(d) while n % d == 0: n //= d d += 1 if n > 1: factors.append(n) return tuple(factors) def rule(a, b, v): return gcd(min(a, b), v) > 1 and gcd(max(a, b), v) == 1 def link(a, b): return any(max(a, b) % p != 0 for p in prime_divisors(min(a, b))) def possible(a, b, v, used): if v in used or not rule(a, b, v) or not link(b, v): return False if v < b and len(prime_divisors(v)) == 1: return any(w not in used and rule(b, v, w) and link(v, w) for w in range(1, v)) return True def check(condition, message): if not condition: raise ValueError(message) def main(): prefix = [1, 4, 9] used = set(prefix) while len(prefix) < 477: a, b = prefix[-2:] v = next((v for v in range(1, 964) if possible(a, b, v, used)), None) check(v is not None, "No candidate in the certified range") prefix.append(v) used.add(v) nonprimes = {v for v in range(1, 529) if prime_divisors(v) != (v,)} check(len(used) == 477 and max(used) == 963, "Size or maximum") check(prefix[-2:] == [527, 578], "End of prefix") check(len(nonprimes) == 429 and nonprimes <= used, "Nonprime coverage") check(529 not in used, "Witness already occurs") check(all(rule(*prefix[i-2:i+1]) for i in range(3, 477)), "Triple rule") check(rule(527, 578, 1023) and gcd(578, 1023) == 1, "Tail splice") encoded = ",".join(map(str, prefix)).encode("ascii") print("length=477 maximum=963 last=(527,578)") print("nonprimes_below_529=429 contains_529=False") print("sha256=" + sha256(encoded).hexdigest()) if __name__ == "__main__": main()