login
Smallest k such that the concatenation 123...(k-1) k (k-1)...321 ( a concatenation of natural numbers from 1 to k and back to 1) is a multiple of prime(n), or 0 if no such number exists.
2

%I #9 Jun 10 2018 21:12:18

%S 0,3,0,6,2,6,109,103,100001,1006,17,3,5,103,1000002,100012,1019,1002,

%T 1001,16,8,105,1036,104,1002,4,100000000009,100004,52,156,10000000012,

%U 1062,8,1002,28,102,1011,1000062,30,10001,118,52,43,10058,34,47

%N Smallest k such that the concatenation 123...(k-1) k (k-1)...321 ( a concatenation of natural numbers from 1 to k and back to 1) is a multiple of prime(n), or 0 if no such number exists.

%e a(5) = 2 as 121 is a multiple of 11.

%o (PARI) { a(n) = local(p,c10,z,u,v,l,k,lk,L,q); p=prime(n); c10=Mod(10,p); z=znorder(c10); u=v=Mod(1,p); l=1; k=2; L=List(); while(1, lk=1+log(k+0.1)\log(10); if(k==10^(lk-1), L=List()); if( u*c10^(l+lk)+k*c10^l+v==0, return(k)); q=0; t=[u,v,k%p,l%z]; for(j=1,#L,if(t==L[j], q=1+#L-j)); if(q, k+=((10^lk-1-k)\q)*q; L=List(), listput(L,t)); u=u*c10^lk+k; v+=k*c10^l; l+=lk; k++) } \\ _Max Alekseyev_, Sep 11 2009

%Y Cf. A077180, A077181, A077182, A077183, A077184, A077186, A077188.

%K base,nonn

%O 1,2

%A _Amarnath Murthy_, Nov 01 2002

%E 3 more terms from _Erich Friedman_, Aug 08 2005

%E Extended by _Max Alekseyev_, Sep 11 2009