Learning about the quadratic residues mod $n$ (link to Wikipedia), "$qr\ mod\ n$" for short, I made some tests focused on those $qr \in [1,n-1]$ (not including the quadratic residue $0$) and stumbled upon this possible property, :
(1) $\forall p\in\Bbb P$, $p > 7$, $p+1 \mid \prod_{[1,p]} \text{qr modulo $p+1$}$
In other words, it seems that for any prime number $p$ greater that $7$, $p+1$ is a factor of the product of the set of quadratic residues mod $(p+1)$ of the interval $[1,p]$ (I mean, $0$ is not included).
E.g.:
$n=30=p+1=29+1$,
$qr\ mod\ 30=\{0,1,4,6,9,10,15,16,19,21,24,25\}$,
$\prod_{[1,29]} (qr\ mod\ 30) = 1\cdot4\cdot6\cdot9\cdot10\cdot15\cdot16\cdot19\cdot21\cdot24\cdot25=124104960000$,
and $30\mid \prod (qr\ mod\ 30)(=124104960000)$.
This is a very brute-force quick Python test for $[1,2\cdot 10^4]$:
def qrmn():
from sympy import is_quad_residue
from gmpy2 import is_prime, mul, mpz
def list_qrmn(n):
lqrmn = []
totprod = mpz(1)
for i in range (1,n):
if is_quad_residue(i,n):
lqrmn.append(i)
totprod = mul(totprod,i)
return lqrmn, totprod
for n in range (8,20000):
if is_prime(n):
lqrmn, totprod = list_qrmn(n+1)
if totprod%(n+1)==0:
print("SUCCESS: " + str(n))
else:
print("ERROR: " + str(n))
qrmn()
So my question is: why does (1) happen? I am sure that it is due to the properties of the quadratic residues, but my theoretical knowledge is very basic so any help is very appreciated.
Thank you!
Let $n=\prod_{1}^{k}p_i^{\alpha_i}$. Assume $k>1$, then one of your quadratic residues is of the form $(p_i^{\alpha_i})^2 + rn$ for each $i$. Therefore the product of all of the quadratic residues contains one factor of the form $\prod_{1}^{k}p_i^{\alpha_i} + \lambda n = n(1 + \lambda)$ which is clearly divisible by $n$.
I will leave the case of $n$ being a prime power to you. Try finding out which prime powers it works for and which ones it does not. Note that it is not really important if $n-1$ is a prime.