OFFSET
1,5
COMMENTS
Let f(0) = 0, f(k+1) = (f(k)^2+f(k)+1) mod n, then a(n) is the smallest i such that f(i) = f(j) for some j > i.
EXAMPLE
A002065(n) mod 4: 0, (1, 3). {A002065(n) mod 4} enters into the cycle (1, 3) from the 1st term on, so a(4) = 1.
A002065(n) mod 7: 0, (1, 3, 6). {A002065(n) mod 7} enters into the cycle (1, 3, 6) from the 1st term on, so a(7) = 1.
A002065(n) mod 11: 0, 1, 3, (2, 7). {A002065(n) mod 11} enters into the cycle (2, 7) from the 3rd term on, so a(11) = 3.
PROG
(PARI) a(n) = my(v=[0], k); for(i=2, n+1, k=(v[#v]^2+v[#v]+1)%n; v=concat(v, k); for(j=1, i-1, if(v[j]==k, return(j-1))))
CROSSREFS
KEYWORD
nonn
AUTHOR
Jianing Song, Oct 26 2019
STATUS
approved