Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		table := make([]bool, 10001)
		now := make([]int, 10001)
		count := make([]int, 10001)
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		index := 0
		for i := 1; i < a; i++ {
			val := i*i%a
			if !table[val] {
				table[val] = true
				now[index] = val
				index++
			}
		}
		for i := 0; i < index; i++ {
			for j := i+1; j < index; j++ {
				t := now[i] - now[j]
				if t < 0 {
					t += a
				}
				if t > (a-1)/2 {
					t = a - t
				}
				count[t]++
			}
		}
		for i := 1; i <= a/2; i++ {
			fmt.Println(count[i]*2)
		}
	}
}

Python: import array
import math

SQUARE_NUM = [item ** 2 for item in range(1, 5001)]


def is_prime_number(num):
    if num == 2:
        return True

    if num < 2 or num % 2 == 0:
        return False

    for divisor in range(3, int(math.sqrt(num)) + 1, 2):
        if num % divisor == 0:
            return False

    return True


while True:
    num = int(input())

    if num == 0:
        break

    half_num = num // 2

    if num % 4 == 3 and is_prime_number(num):
        count = str(num // 2 - 1)
        output = [count] * (half_num - 1)
    else:

        mod = [item % num for item in SQUARE_NUM[:half_num]]
        unique_mod = list(set(mod))

        counter = array.array("i", [0] * half_num)

        for index, item in enumerate(unique_mod, 1):
            for item2 in unique_mod[index:]:

                subtract = item - item2

                if subtract < 0:
                    subtract += num

                if half_num < subtract:
                    subtract = num - subtract

                counter[subtract - 1] += 2

        output = [str(item) for item in counter]

    print("\n".join(output))

Python: # 0142 - Nature of Prime Numbers

while True:
	n = int(input())
	if n == 0: break

	_max = int((n - 1) / 2)
	ns = set([x * x % n for x in range(1, _max + 1)])
	cs = {}

	for i in ns:
		for j in ns:
			if i > j:
				m = i - j
				if m > _max: m = n - m
				cs[m] = cs.setdefault(m, 0) + 1
	for i in range(1, _max + 1):
			print(i * 2)

Python: # 0142 - Nature of Prime Numbers

while True:
	n = int(input())
	if n == 0: break

	_min = 0
	_max = int((n - 1) / 2)

	print(_min, _max)

	ns = set([ x * x % n for x in range(1, n)])
	count  = {}
	for (i, j) in [(i, j) for i in ns for j in ns if i < j]:
		m = i - j
		if m < _min: m = n + m
		if m > _max: m = n - m
		count.setdefault(m, 0)
		count[m] += 1

	for i in range(1, int((n - 1) / 2 + 1)):
		print(count[i] * 2)

Python: while True:
    n = int(input())
    if n == 0:
        break

    a = []
    for i in range(1, (n+1)//2):
        k = i**2 % n
        if not k in a:
            a.append(k)

    #print(a)
    a.sort()
    b = [0 for i in range((n-1)//2)]
    for i in range(len(a)):
        for j in range(i+1, len(a)):
            k = a[j] - a[i]
            if k > (n-1)//2:
                k = n - k
            b[k-1] += 1

    for i in range(len(b)):
        print(2*b[i])

Python: # 0142 - Nature of Prime Numbers

while True:
	n = int(input())
	if n == 0: break

	_max = int((n - 1) / 2)
	ns = set([x * x % n for x in range(1, _max + 1)])
	cs = {}

	for i in ns:
		for j in ns:
			if i > j:
				m = i - j
				if m > _max: m = n - m
				cs[m] = cs.setdefault(m, 0) + 2
	s = ''
	for i in range(1, _max + 1):
			s += str(cs[i]) + '\n'
	print(s)

Python: import itertools
def func(n):
  rest= {i**2%n for i in range(1,n)}
  count=[0]*n
  for x,y in itertools.combinations(rest,2):
    count[x-y] +=2
  for i in range(n//2):print(count[i+1]+count[n-i-1])
while True:
  n = int(input())
  if n == 0:break
  func(n)

Python: from collections import Counter

def func(n):
  dic = Counter()
  rest = []
  for i in range(1, n):
    rest.append(i ** 2 % n)
  rest = list(set(rest))
  rest.sort()
  lenr = len(rest)
  
  for i in range(lenr):
    for j in range(i + 1, lenr):
      x, y = rest[i], rest[j]
      if y - x > n // 2:
        dic[n - (y - x)] += 2
      else:
        dic[y - x] += 2

  for i in range(1, (n + 1) // 2):
    print(dic[i])
while True:
  n = int(input())
  if n == 0:
    break
  func(n)

Python: from itertools import combinations as C

def hoge(tmp, a, b, t, n):
    v = a-b
    if v < 0:
        v = a-b+n
    if v > t:
        v = n-v
    tmp.append(v)

while True:
    n = int(input())
    if n == 0:
        break
    ab = []
    for i in range(1, n):
        ab.append(i**2%n)
    t = (n-1) // 2
    tmp = []
    for p in list(C(set(ab), 2)):
        a, b = p[0], p[1]
        hoge(tmp, a, b, t, n)
        hoge(tmp, b, a, t, n)
    for i in range(1, t+1):
        print(tmp.count(i))

Python: # 0142 - Nature of Prime Numbers

while True:
	n = int(input())
	if n == 0: break

	_max = int((n - 1) / 2)

	ns = set([ x * x % n for x in range(1, n)])
	count  = [0 for i in range(0, int((n - 1) / 2) + 1)]
	for i in ns:
		for j in ns:
			if i > j:
				m = i - j
				if m > _max: m = n - m
				count[m] += 1
	for i in count:
			if i > 0: print(i * 2)

Python: # 0142 - Nature of Prime Numbers

while True:
	n = int(input())
	if n == 0: break

	_min = 0
	_max = int((n - 1) / 2)

	print(_min, _max)

	ns = set([ x * x % n for x in range(1, n)])
	count  = {}
	for i in ns:
		for j in ns:
			if i < j:
				m = i - j
				if m < _min: m = n + m
				if m > _max: m = n - m
				count.setdefault(m, 0)
				count[m] += 1
	for i in range(1, int((n - 1) / 2 + 1)):
		print(count[i] * 2)

Python: from itertools import combinations as C

def hoge(tmp, a, b, t, n):
    v = a-b
    if v < 0:
        v = a-b+n
    if v > t:
        v = n-v
    if v < t+1:
        tmp.append(v)

while True:
    n = int(input())
    if n == 0:
        break
    r = set(pow(i, 2, n) for i in range(1, n))
    t = (n-1) // 2
    tmp = []
    for a, b in C(r, 2):
        hoge(tmp, a, b, t, n)
        hoge(tmp, b, a, t, n)
    for i in range(1, t+1):
        print(tmp.count(i))

Python: # AOJ 0142 Nature of Prime Numbers
# Python3 2018.6.22 bal4u

MAX = 10000
HALF = 5003

not_prime = [0]*MAX
tbl = [3,  5,  7, 11, 13, 17, 19, 23, 29, 31, \
 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
def sieve():
	for i in tbl:
		for j in range(i*i, MAX, i): not_prime[j] = 1
sieve()

while 1:
	n = int(input())
	if n == 0: break
	k = n >> 1
	# 4m+3の素数
	if not_prime[n] == 0 and (n & 3) == 3:
		print(*[k-1]*k, sep='\n')
		continue;

	# 他の奇数についてはまじめに計算
	d = [0]*HALF
	f = [0]*HALF
	a = []
	m = 0;
	for i in range(1, k+1):
		b = i*i % n;
		if f[b] == 0:
			f[b] = 1
			a.append(b)
	for i in range(len(a)):
		for j in range(i):
			b = a[i]-a[j]
			if b == 0: continue
			if b < 0: b += n
			if b > k: b = n-b
			d[b] += 1
	for i in range(1, k+1):	print(d[i]<<1)

Python: from collections import Counter

while True:
    num = int(input())

    if num == 0:
        break

    half_num = num // 2

    mod = [item ** 2 % num for item in range(1, num)]
    unique_mod = list(set(mod))

    counter = Counter()

    for item in unique_mod:
        for item2 in unique_mod:
            if item != item2:
                subtract = item - item2

                if subtract < 0:
                    subtract += num
                if half_num < subtract:
                    subtract = num - subtract

                counter[subtract] += 1

    output = ""

    for index in range(1, half_num):
        output += str(counter[index])
        output += "\n"
    output += str(counter[half_num])

    print(output)