#!/usr/bin/env python3 import json,urllib.request as u,time a,b=5000,6000 t=time.time() r=json.load(u.urlopen(u.Request('https://factordb.com/rpc',json.dumps(dict(jsonrpc='2.0',id=1,method='get_family',params=dict(expr='10^18+n',start=a,limit=b-a,factors=True))).encode(),{'Content-Type':'application/json'}),timeout=6))['result']['members'] def bad(q):return q%3==1 and pow(2,(q-1)//3,q)!=1 g=[m['x'] for m in r if all(f['exponent']%3==0 or not bad(int(f['base'])) for f in m['factors'])] print(a,b,len(r),len(g),sum(g),'last',r[-1]['x'],'unfactored',[m['x'] for m in r if any(f['status']!='P' for f in m['factors'])],'seconds',time.time()-t))