big = 1 000 000
s = 0
S = Set([])
unseen = 1
seen(v) = if (v < big, bit test(s, v), set search(S, v))
see(v) = if (v < big, s = bit or(s, 2^v), S = set union(S, Set([v]))); while (seen(unseen), unseen++)

T = matrix(W=100,W)

{
	see(0);
	m = 0;
	for (d=1, W,
		for (k=1, d,
			n=d+1-k;

			t = sum(nn=1, n, sum(kk=1, k, T[nn,kk]));
			r = n*k;
			forstep (v=r*(unseen\r) + lift(-Mod(t, r)), oo, r,
				if (!seen(v),
					print (m++ " " v);
					see(T[n,k] = v);
					break;
				);
			);
		);
	);
}

quit