OFFSET
1,2
COMMENTS
Sort mod n numbers {0,1,...,n-1} in ascending order. For each modular number i, write 1 if i is a quadratic residue mod n (i.e., it has a square root), else write 0. The corresponding n-bit number is a(n).
LINKS
Adnan Baysal, Table of n, a(n) for n = 1..1000
EXAMPLE
For n = 10, quadratic residues are 0, 1, 4, 5, 6, 9 so a(10) is 1100111001 in binary which is 825.
MATHEMATICA
f[n_] := Total[ 2^(n -1 -Union[ Mod[ Range[0, n - 1]^2, n]] )]; Array[f, 34] (* Robert G. Wilson v, Dec 28 2016 *)
PROG
(Python)
def qr_distribution(N):
QR = []
QN = []
for i in range(N):
t = (i*i)%N
if t not in QR: QR.append(t)
for i in range(N):
if i not in QR: QN.append(i)
out = 0
for i in range(0, N):
out *= 2
if i in QR: out += 1
return out
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Adnan Baysal, Dec 26 2016
STATUS
approved