OFFSET
2,1
COMMENTS
a(n) <= n-2 for n >= 4, because (n+1)^(n-2) == (n-1)^2 (mod n^2).
If 2*n+1 is a perfect power, a(n) = 2.
Is there a characterization of the numbers n where a(n) = n-2? Conjecture I: if n <> 7 is a safe prime (A005385), then a(n) = n-2. Conjecture II: if n <> 22, n <> 1822 and n+1 is a safe prime, then a(n) = n-2. - Chai Wah Wu, Oct 13 2020
If n is in the sequence with recurrence b(n+2) = 98*b(n+1)-b(n)+32, b(0)=0, b(1)=36, then (n+1)^4 mod n^3 = 1 + 4*n + 6*n^2 is a square, so a(n) <= 4. - Robert Israel, Oct 14 2020
LINKS
Chai Wah Wu, Table of n, a(n) for n = 2..5853
EXAMPLE
a(2) = 6 because 3^6 mod 2^4 = 3^2.
a(13) = 2 because 14^2 mod 13^2 = 3^3.
MAPLE
f:= proc(n) local k, x, j, F;
for k from 2 to n-2 do
x:= (n+1)^k;
for j from 2 to floor(k*log[n](n+1)) do
F:= ifactors(x mod (n^j))[2];
if igcd(op(map(t -> t[2], F))) > 1 then return k fi
od od
end proc:
f(2):= 6: f(3):= 4:
map(f, [$2..40]);
MATHEMATICA
f[n_] := Module[{k, x, j, F}, For[k = 2, k <= n-2, k++, x = (n+1)^k; For[j = 2, j <= Floor[k*Log[n, n+1]], j++, F = FactorInteger[Mod[x, n^j]]; If[GCD@@F[[All, 2]] > 1, Return[k] ]]]];
f[2] = 6; f[3] = 4;
Map[f, Range[2, 40]] (* Jean-François Alcover, May 28 2023, after Maple program *)
PROG
(Python)
from gmpy2 import is_power
def A338136(n):
k, n2, m = 2, n**2, (n+1)**2
while True:
j, nj = 2, n2
while nj < m:
r = m % nj
if r > 1 and is_power(r):
return k
nj *= n
k += 1
m *= n+1 # Chai Wah Wu, Oct 13 2020
CROSSREFS
KEYWORD
nonn
AUTHOR
J. M. Bergot and Robert Israel, Oct 12 2020
STATUS
approved