%I #30 May 12 2023 12:00:00
%S 1,2,3,2,6,6,12,2,24,6,30,6,30,22,6,2,30,24,90,6,33,42,59,6,40,30,72,
%T 22,77,6,73,2,66,30,66,24,72,90,60,6,99,66,122,42,48,118,144,6,432,40,
%U 60,30,132,72,66,22,129,154,870,6,210,146,264,2,60,66,224,30
%N a(n) = maximum eventual period of z := z^2 + c (mod n), for Gaussian integers z, c.
%C Note that this is the maximum over all possible initial z.
%C From _Robert Israel_, Aug 29 2016: (Start)
%C If n is divisible by 4, then a(n) = a(n/2).
%C In particular, a(n) = 2 if n > 1 is a power of 2.
%C Are there any other n with a(n) = 2? (End)
%e For n = 3, c = 2+i:
%e z_0 = 0.
%e z_1 = (z_0)^2 + 2+i = 2+ i (mod 3).
%e z_2 = (z_1)^2 + 2+i = 2+2i (mod 3).
%e z_3 = (z_2)^2 + 2+i = 2 (mod 3).
%e z_4 = (z_3)^2 + 2+i = i (mod 3).
%e z_5 = (z_4)^2 + 2+i = 1+ i (mod 3).
%e z_6 = (z_5)^2 + 2+i = 2 (mod 3) = z_3.
%e So the eventual period is 3, which is the maximum possible over all c and z_0 when n = 3.
%p f:= proc(N)
%p local pmax,R,S,T,z,a,b,c,x,y,found,zpd,count;
%p pmax:= 0;
%p for a from 0 to N-1 do
%p for b from 0 to N-1 do
%p c:= a+b*I;
%p S:= {}:
%p for x from 0 to N-1 do
%p for y from 0 to N-1 do
%p z:= x+I*y;
%p if not member(z,S) then
%p T:= {z};
%p R[z]:= 0;
%p found:= false;
%p for count from 1 do
%p z:= expand(z^2 + c) mod N;
%p if member(z,S) then break fi;
%p if member(z,T) then found:= true; zpd:= count - R[z]; break fi;
%p R[z]:= count;
%p T:= T union {z};
%p od;
%p S:= S union T;
%p if found and zpd > pmax then
%p pmax:= zpd fi;
%p fi;
%p od od;
%p od od;
%p pmax
%p end proc:
%p map(f, [$1..30]); # _Robert Israel_, Aug 29 2016
%t f[n_] := Module[{pmax = 0, R, S, T, z, a, b, c, x, y, found, zpd, count},
%t For[a = 0, a <= n - 1, a++,
%t For[b = 0, b <= n - 1, b++, c = a + b*I; S = {};
%t For[x = 0, x <= n - 1, x++,
%t For[y = 0, y <= n - 1, y++, z = x + y*I;
%t If[!MemberQ[S, z], T = {z}; R[z] = 0; found = False;
%t For[count = 1, True, count++,
%t z = Mod[Expand[z^2 + c], n];
%t If[MemberQ[S, z], Break[] ];
%t If [MemberQ[T, z], found = True; zpd = count -
%t R[z]; Break[]]; R[z] = count;
%t T = Union[T, {z}]]; S = Union[S, T];
%t If [found && zpd > pmax, pmax = zpd]]]]]];
%t pmax];
%t Table[f[n], {n, 1, 20}] (* _Jean-François Alcover_, May 12 2023, after _Robert Israel_ *)
%K nonn
%O 1,2
%A _Luke Palmer_, Aug 21 2016
%E More terms from _Robert Israel_, Aug 29 2016