upto(n) = {t = 2; res = List(); printat = 10^6; qchecks = 0;
	while(t < n, 
		
		if(qchecks > printat, 
			print1(qchecks \ 10^6", "t", "); 
			printat+=10^6
		);
		ct = t;
		for(i = 3, ct-1, 
			qchecks++; 
			ct = nxt(ct, i);
			if(ct != t,
				t = ct; 
				next(2)
			)
		); 
		print(); print(); 
		listput(res, t); 
		print(res); 
		print(); 
		t++
	); print(qchecks); res
}

nxt(n, b) = {
	my(d = concat(0, digits(n, b)), bm1 = b-1); 
	for(i = 2, #d, 
		if(d[i] == bm1, 
			forstep(j = i-1, 1, -1,
				if(d[j] < bm1,
					d[j]++;
					for(k = j+1, #d, 
						d[k] = 0;
					);
					return(fromdigits(d, b))
				)
			)	
		)
	); return(n)
}