login
Least k such that prime(n) mod k = n or 0 if no such k exists.
0

%I #28 Jul 11 2024 02:08:49

%S 0,0,0,0,6,7,10,11,14,19,20,25,14,29,16,37,21,43,24,51,26,57,30,65,36,

%T 75,38,79,40,83,32,33,52,35,38,115,40,125,64,133,46,139,74,149,76,51,

%U 82,175,89,179,91,187,94,197,101,69,106,71,109,221,74,77,122,247

%N Least k such that prime(n) mod k = n or 0 if no such k exists.

%C We observe pairs of consecutive numbers: (6, 7), (10, 11), (19, 20), (32, 33), (93, 94), (118, 119), (242, 243), (302, 303), (215, 216), ...

%C As k > n we have prime(n) = m*k + n. As prime(n) > n for all n we have m >= 1 and so prime(n) >= k + n > n + n = 2*n. But prime(n) < 2*n for n <= 4 so a(n) = 0 for n <= 4. - _David A. Corneth_, Jul 08 2024

%e a(5) = 6 because prime(5) mod 6 = 11 mod 6 = 5, and there is no k < 6 such that prime(5) mod k = 5.

%p nn:=10^7:

%p for n from 1 to 100 do:

%p ii:=0:

%p for k from 1 to nn while(ii=0)

%p do:

%p if irem(ithprime(n),k)=n

%p then ii:=1:printf(`%d, `,k):

%p else fi:

%p od:

%p if ii=0

%p then printf(`%d, `,0):

%p else fi:

%p od:

%t Table[k=1;While[Mod[Prime[n],k] !=n,k++];k,{n,5,70}]

%o (PARI) a(n) = if (n<5, 0, my(k=1); while((prime(n) % k) != n, k++); k); \\ _Michel Marcus_, Jul 06 2024

%o (PARI) first(n) = {

%o n = max(n, 4);

%o my(res = vector(n), t = 4);

%o forprime(p = 11, oo,

%o t++;

%o if(t > n,

%o return(res);

%o );

%o d = divisors(p - t);

%o for(i = 1, #d,

%o if(d[i] > t,

%o res[t] = d[i];

%o break

%o );

%o );

%o );

%o } \\ _David A. Corneth_, Jul 07 2024

%Y Cf. A000040, A014689.

%K nonn

%O 1,5

%A _Michel Lagneau_, Jul 06 2024