login
Number of squares in multiplicative group modulo n.
23

%I #70 Oct 31 2023 03:09:00

%S 1,1,1,1,2,1,3,1,3,2,5,1,6,3,2,2,8,3,9,2,3,5,11,1,10,6,9,3,14,2,15,4,

%T 5,8,6,3,18,9,6,2,20,3,21,5,6,11,23,2,21,10,8,6,26,9,10,3,9,14,29,2,

%U 30,15,9,8,12,5,33,8,11,6,35,3,36,18,10,9,15,6,39,4,27,20,41,3,16,21

%N Number of squares in multiplicative group modulo n.

%C a(n) is the number of different diagonal elements in Cayley table for multiplicative group modulo n. But the fact that the same number of different elements are on the diagonal of the Cayley table does not mean in every case that these groups are isomorphic. - _Artur Jasinski_, Jul 03 2010

%C The number of quadratic residues modulo n that are coprime to n. These residues are listed in A096103. - _Peter Munn_, Mar 10 2021

%D Daniel Shanks, Solved and Unsolved Problems in Number Theory, 4th ed. New York: Chelsea, p. 95, 1993.

%H Antti Karttunen, <a href="/A046073/b046073.txt">Table of n, a(n) for n = 1..16384</a>

%H Steven R. Finch and Pascal Sebah, <a href="https://arxiv.org/abs/math/0604465">Square and Cubes Modulo n</a>, arXiv:math/0604465 [math.NT], 2006-2016.

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/ModuloMultiplicationGroup.html">Modulo Multiplication Group</a>.

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

%F a(n) * A060594(n) = A000010(n) = phi(n) (This gives a formula for a(n) using the one in A060594(n) ). - Sharon Sela (sharonsela(AT)hotmail.com), Mar 09 2002

%F Multiplicative with a(2^e) = 2^max(e-3,0), a(p^e) = (p-1)*p^(e-1)/2 for p an odd prime.

%F Sum_{k=1..n} a(k) ~ c * n^2/sqrt(log(n)), where c = (43/(80*sqrt(Pi))) * Product_{p prime} (1+1/(2*p))*sqrt(1-1/p) = 0.24627260085060864229... (Finch and Sebah, 2006). - _Amiram Eldar_, Oct 18 2022

%p F:= n -> nops({seq}(`if`(igcd(t,n)=1,t^2 mod n,NULL), t=1..floor(n/2))):

%p 1, seq(F(n), n=2..100); # _Robert Israel_, Jan 04 2015

%p # 2nd program

%p A046073 := proc(n)

%p local a,p,e,pf;

%p a := 1;

%p for pf in ifactors(n)[2] do

%p p := op(1,pf) ;

%p e := op(2,pf) ;

%p if p = 2 then

%p a := a*p^max(e-3,0) ;

%p else

%p a := a*(p-1)/2*p^(e-1) ;

%p end if;

%p end do:

%p a ;

%p end proc: # _R. J. Mathar_, Oct 03 2016

%t Table[EulerPhi[n]/Sum[Boole[Mod[k^2, n] == 1] + Boole[n == 1], {k, n}], {n, 86}] (* or *)

%t Table[Apply[Times, FactorInteger[n] /. {p_, e_} /; p > 0 :> Which[p == 1, 1, p == 2, 2^Max[e - 3, 0], True, (p - 1) p^(e - 1)/2]], {n, 86}] (* _Michael De Vlieger_, Jul 18 2017 *)

%o (PARI)

%o A060594(n) = if(n<=2, 1, 2^#znstar(n)[3]); \\ This function from _Joerg Arndt_, Jan 06 2015

%o A046073(n) = eulerphi(n)/A060594(n); \\ _Antti Karttunen_, Jul 17 2017, after Sharon Sela's Mar 09 2002 formula.

%o (PARI) A046073(n)=if(n>4,(n=znstar(n))[1]>>#n[3],1) \\ Avoids duplicate computation of phi(n). - _M. F. Hasler_, Nov 27 2017, typo fixed Mar 11 2021

%o (Scheme) (define (A046073 n) (cond ((= 1 n) n) ((even? n) (* (A000079 (max (- (A007814 n) 3) 0)) (A046073 (A028234 n)))) (else (* (/ 1 2) (- (A020639 n) 1) (/ (A028233 n) (A020639 n)) (A046073 (A028234 n)))))) ;; _Antti Karttunen_, Jul 17 2017, after the given multiplicative formula.

%o (Python)

%o from sympy import factorint, prod

%o def a(n): return 1 if n==1 else prod([2**max(e - 3, 0) if p==2 else (p - 1)*p**(e - 1)//2 for p, e in factorint(n).items()])

%o print([a(n) for n in range(1, 51)]) # _Indranil Ghosh_, Jul 17 2017

%Y Cf. A046072, A007735, A060594, A000010, A087692, A000224.

%Y Row lengths of A096103.

%Y Positions of ones: A018253.

%K nonn,easy,mult

%O 1,5

%A _Eric W. Weisstein_

%E Edited and verified by _Franklin T. Adams-Watters_, Nov 07 2006