Hamming numbers: Difference between revisions

canonicalized
(canonicalized)
Line 8,136:
This is a basic implementation; finding the millionth term requires 1 second and 54 MB. Much better algorithms exist.
<syntaxhighlight lang="parigp">Hupto(n)={
my(vr=vectorVec([1],n),x2=2,x3v=primes(3),x5[v1,v2,v3]=5v,i=1,j=1,k=1,t);
v[1]=1;
for(m=2,n,
vr[m]=t=min(x2v1,min(x3v2,x5v3));
if(x2v1 == t, x2v1 = v[1] * r[i++] << 1);
if(x3v2 == t, x3v2 = 3v[2] * vr[j++]);
if(x5v3 == t, x5v3 = 5v[3] * vr[k++]);
);
vr
};
H(n)=Hupto(n)[n];
15

edits