login
Maximum value of powers of 2 mod n.
2

%I #31 May 14 2023 09:17:13

%S 0,1,2,2,4,4,4,4,8,8,10,8,12,8,8,8,16,16,18,16,16,20,18,16,24,24,26,

%T 16,28,16,16,16,32,32,32,32,36,36,32,32,40,32,42,40,38,36,42,32,46,48,

%U 32,48,52,52,52,32,56,56,58,32,60,32,32,32,64,64,66,64,64

%N Maximum value of powers of 2 mod n.

%H Rémy Sigrist, <a href="/A327649/b327649.txt">Table of n, a(n) for n = 1..8192</a>

%H Rémy Sigrist, <a href="/A327649/a327649.png">Colored scatterplot of the ordinal transform of the first 2^16 terms</a> (colored pixels correspond to n's such that a(n) is a power of 2)

%F a(2^k) = 2^(k-1) for any k > 0.

%F a(2^k+1) = 2^k for any k >= 0.

%F a(2^k-1) = 2^(k-1) for any k > 1.

%F If n = 2^j * r with r odd > 1 then a(n) = 2^j * a(r). - _Robert Israel_, Feb 15 2023

%e For n = 10:

%e - the first powers of 2 mod 10 are:

%e k 2^k mod 10

%e -- ----------

%e 0 1

%e 1 2

%e 2 4

%e 3 8

%e 4 6

%e 5 2

%e - those values are eventually periodic, the maximum being 8,

%e - hence a(10) = 8.

%p f:= proc(n) local S,k,x,m;

%p x:= 1; S:= {1}; m:= 1;

%p for k from 1 do

%p x:= 2*x mod n;

%p if member(x,S) then return m fi;

%p S:= S union {x};

%p m:= max(m,x)

%p od

%p end proc:

%p f(1):= 0:

%p map(f, [$1..100]); # _Robert Israel_, Feb 15 2023

%t a[n_] := PowerMod[2, Range[0, n-1], n] // Max;

%t Table[a[n], {n, 1, 1000}] (* _Jean-François Alcover_, May 14 2023 *)

%o (PARI) a(n) = { my (p=1%n, mx=p); while (1, p=(2*p)%n; if (mx<p, mx=p, mx==p || p==0, return (mx))) }

%Y Cf. A000079, A062170, A047210, A327650.

%K nonn,look

%O 1,3

%A _Rémy Sigrist_, Sep 21 2019