s = 0
seen(v) = bittest(s, v)
see(v) = s = bitor(s, 2^v)

base = 10

{
	n=0;
	for (w=1, oo,
		my (m=base^w);
		forprime (p=1, oo,
			my (l=max(1, #digits(p, base)));
			forstep (s=l-w, 0, -1,
				my (d=(p\(base^s))%m);
				if (!seen(d),
					see(d);
					print (n++ " " d);
					if (n==1 000 000,
						break (3);
					);
				);
			);
			if (n==m,
				break;
			);
		);
	);
}

quit