A328702 Start with 0, a(n) is the smallest number of iterations: x -> (x^2+x+1) mod n needed to run into a cycle.
0, 1, 0, 1, 2, 1, 1, 1, 2, 2, 3, 1, 0, 1, 2, 1, 3, 2, 4, 2, 1, 3, 1, 1, 2, 1, 4, 1, 1, 2, 2, 1, 3, 3, 2, 2, 2, 4, 0, 2, 4, 1, 5, 3, 2, 1, 3, 1, 3, 2, 3, 1, 9, 4, 3, 1, 4, 1, 6, 2, 0, 2, 2, 1, 2, 3, 7, 3, 1, 2, 2, 2, 3, 2, 2, 4, 3, 1, 4, 2, 4, 4, 14, 1, 3, 5, 1, 3, 8, 2, 1
Offset: 1
Keywords
Examples
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. A002065(n) mod 19: 0, 1, 3, 13, (12, 5). {A002065(n) mod 19} enters into the cycle (12, 5) from the 4th term on, so a(19) = 4. A002065(n) mod 61: (0, 1, 3, 13). {A002065(n) mod 61} enters into the cycle (0, 1, 3, 13) from the very beginning, so a(61) = 0.
Programs
-
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))))
Comments