I,R,O=input,range,print L=9**5 P=[] C=[0]*L for i in R(2,L): if C[i]<1: P+=[i] j=i*i while j1: for m in[n*e for n in D[-r:]]: D+=[m] if A<=m0])