tribonacci(n) = ([0,1,0; 0,0,1; 1,1,1]^n)[2,1] fromtrib(n) = { my (v=0, j); while (n, n-=2^j=valuation(n,2); v+=tribonacci(3+j); ); return (v); } nb = vector(tribonacci(3+N=13)-1) for (m=1, 2^N, v=fromtrib(m); if (v<=#nb, nb[v]++)) vv = vector(#nb, n, vector(nb[n])) kk = vector(#nb) for (m=1, 2^N, v=fromtrib(m); if (v<=#nb, vv[v][kk[v]++]=m)) print ("0 0"); i=0; for (n=1, #vv, for (k=1, #vv[n], print (i++ " " vv[n][k]))) quit