#!/usr/bin/env python3 import time t=time.time() A=10**18 N=10001 R=list(range(A,A+N)) bad=bytearray(N) L=1000000 s=bytearray([1])*(L+1) s[0]=s[1]=0 for p in range(2,L+1): if s[p]: if p*p<=L: for j in range(p*p,L+1,p):s[j]=0 h=p>3 and p%3==1 and pow(2,(p-1)//3,p)!=1 for i in range((-A)%p,N,p): e=0 while R[i]%p==0: R[i]//=p e+=1 if h and e%3:bad[i]=1 print('bad',sum(bad),'residual',sum(not bad[i] and R[i]>1 for i in range(N)),'ones',sum(not bad[i] and R[i]==1 for i in range(N)),'secs',time.time()-t)