/* A100769 Beginning with 1, least positive integer not occurring earlier such that the n-th partial concatenation is a multiple of n. */ used = vector(50 000); /* terms used so far */ head = 0 /* concatenation of the first terms */ nexta(n) = my(l=1,z,s); \ z = -Mod(head*10+1,n); \ while(1, \ forstep(s=10^(l-1)+lift(z), 10^l-1, n, \ if (used[s]==0, \ used[s]=1; \ head = head*10^l+s; \ return(s) \ ) \ ); \ l=l+1; \ z=z*10 \ ) for (n=1,10 000,print(n" "nexta(n))) quit