login
Smallest integer m > 1 such that m^(n-1) == 1 (mod n).
5

%I #56 May 05 2014 12:59:25

%S 2,3,2,5,2,7,2,9,8,11,2,13,2,15,4,17,2,19,2,21,8,23,2,25,7,27,26,9,2,

%T 31,2,33,10,35,6,37,2,39,14,41,2,43,2,45,8,47,2,49,18,51,16,9,2,55,21,

%U 57,20,59,2,61,2,63,8,65,8,25,2,69,22,11,2,73,2,75,26

%N Smallest integer m > 1 such that m^(n-1) == 1 (mod n).

%C Composite n are Fermat pseudoprimes to base a(n).

%C For n > 1; (5+(-1)^n)/2 <= a(n) <= n+(-1)^n. If n > 2 and a(n) > 2 then n is composite. - _Thomas Ordowski_, Dec 01 2013

%H T. D. Noe, <a href="/A105222/b105222.txt">Table of n, a(n) for n = 1..10000</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/FermatPseudoprime.html">Fermat Pseudoprime</a>

%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Fermat_pseudoprime">Fermat pseudoprime</a>

%F a(p) = 2 for odd prime p.

%e We have 2^(2-1) == 0, 3^(2-1) == 1 (mod 2), so a(2) = 3.

%t Table[k = 2; While[PowerMod[k, n - 1, n] != 1, k++]; k, {n, 2, 100}] (* _T. D. Noe_, Dec 07 2013 *)

%o (PARI) a(n) = {m = 2; while ((m^(n-1) % n) != lift(Mod(1, n)), m++); m; } \\ _Michel Marcus_, Dec 01 2013

%o (PARI) a(n) = my(m=2); while(Mod(m, n)^(n-1)!=1, m++); m \\ _Charles R Greathouse IV_, Dec 01 2013

%Y Cf. A007535, A181780, A239452.

%K easy,nonn

%O 1,1

%A _Max Alekseyev_, Apr 14 2005