{ /* least proper multiple of n which is a concatenation of 2 or more successive numbers */ lpmcsn(n) = my( len=length(Str(n)), /* length of the multiple */ multiple=0, /* multiple */ l, /* length of first number */ c, /* number of numbers of length l */ first, /* first number */ v0, /* first concatenation */ d, /* delta with next concatenation */ ymax, /* v0+d*ymax is the max term in the familly */ bzt, X0, Y0, g /* bezout */ ); while(multiple==0, for (l=1, len/2, for (c=1,min(len/l,9*10^(l-1)), if (c*l==len, /* all consecutive numbers have the same size */ first = 10^(l-1); v0 = 0; for (i=0,c-1, v0 = v0*10^l+first+i ); d = ((10^l)^c-1)/(10^l-1); ymax = 9*10^(l-1)-c; /* we solve X*n - Y*d = v0 with 1<X and 0<=Y<=ymax */ /* gcd(n,d) must divide v0 */ bzt = bezout(n,d); X0 = bzt[1]; Y0 = bzt[2]; g = bzt[3]; if (v0%g==0, k0 = ceil((g-v0*X0)/d); if ( (g-v0*X0)%d==0, k0 = k0+1 ); k1 = ceil ( v0*Y0 /n ); k2 = floor( (v0*Y0+ymax*g)/n ); kmin = max(k0, k1); if (kmin<=k2, solmin = v0 - (v0*Y0/g - n/g*kmin)*d; if (multiple==0 || multiple>solmin, multiple = solmin ) ) ), /* consecutive numbers have different sizes */ cc = c; ll = l+1; rem = len-c*l; while (rem, mx = min(floor(rem/ll), 9*10^(ll-1)); if (mx==0, break ); cc = cc + mx; rem = rem - mx*ll; ll = ll+1 ); if (rem==0, first = 10^l-c; v0 = 0; for (i=0, cc-1, v0 = eval(concat(v0,Str(first+i))) ); if (v0>n && v0%n==0, if (multiple==0 || multiple>v0, multiple = v0 ) ) ) ) ) ); len = len+1 ); return(multiple) }