\\ first k terms of row n row(n, k) = { my (r=vector(k), s=0, w=0); for (i=1, k, if (n, my (v=valuation(n+n%2,2)); w++; s += r[i] = v; n \= 2^v, r[i] = s; s += r[i]-r[i-w]; ); ); r } tab = vector(D=150, n, row(n, D+1-n)) m=0; for (d=1, D, for (k=1, d, print (m++ " " tab[d+1-k][k]))) quit