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: from array import array
import itertools

while True:
    num = int(input())

    if num == 0:
        break

    half_num = num // 2

    mod = [pow(item, 2, num) for item in range(1, half_num + 1)]
    unique_mod = array("i", sorted(set(mod), reverse=True))

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

    for item, item2 in itertools.combinations(unique_mod, 2):

        subtract = item - item2

        if half_num < subtract:
            subtract = num - subtract

        counter[subtract - 1] += 2

    output = [str(item) for item in counter]
    print("\n".join(output))

Python: import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    N = int(readline())
    if N == 0:
        return False
    if N == 1:
        return True
    *S, = set(i**2 % N for i in range(1, N))
    S.sort()
    L = len(S)
    C = [0]*N
    D = [0]*((N-1)//2)
    for i in range(L):
        a = S[i]
        for b in S[:i]:
            C[a - b] += 2
    for i in range(1, N):
        D[min(i, N-i)-1] += C[i]
    write("\n".join(map(str, D)))
    write("\n")
    return True
while solve():
    ...

Python: # 0142 - Nature of Prime Numbers

pows = [x * x for x in range(1, 10000)]

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

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

	ns = set([x % n for x in pows[0: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: # Aizu Problem 00142: Nature of Prime Numbers
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n = int(input())
    if n == 0:
        break
    inp = sorted(list(set([i**2 % n for i in range(1, n)])))
    table = [0] * (1 + (n - 1) // 2)
    for i in range(len(inp)):
        for j in range(len(inp)):
            if i == j:
                continue
            c = inp[i] - inp[j]
            if c < 0:
                c += n
            if c > (n - 1) // 2:
                c = n - c
            table[c] += 1
    for i in range(1, (n - 1) // 2 + 1):
        print(table[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 = [0 for i in range(0, _max + 1)]

	for i in ns:
		for j in ns:
			if i > j:
				m = i - j
				if m > _max: m = n - m
				cs[m] += 1
	for i in cs:
			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)

	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 < _min: m = n + m
				if m > _max: m = n - m
				count[m] += 1
	for i in count:
			if i > 0: print(i * 2)

Python: from collections import Counter

def func(n):
  dic = Counter()
  rest = list({i ** 2 % n for i in range(1, n)})
  lenr = len(rest)
  rest.sort()
  half = n // 2
  
  for i in range(lenr):
    resti = rest[i]
    for j in range(i + 1, lenr):
      dff = rest[j] - resti
      if dff > half:
        dic[n - dff] += 2
      else:
        dic[dff] += 2

  for i in range(1, half + 1):
    print(dic[i])

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

main()

Python: from collections import Counter

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

while True:
    num = int(input())

    if num == 0:
        break

    half_num = num // 2

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

    counter = Counter()

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

            subtract = item - item2

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

            counter[subtract] += 2

    output = [counter[index] for index in range(1, half_num + 1)]
    output = map(lambda item: str(item), output)
    print("\n".join(output))

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

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

    #print(a)
    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[i] - a[j]
            if k < 0:
                k += n
            if k > (n-1)//2:
                k = n - k
            b[k-1] += 1

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

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])


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

main()

C++: #include <set>
#include <cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;std::set<int>::iterator s,S;for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(s=t.begin();s!=t.end();s++)for(S=s;++S!=t.end();v[i>n/2?n-i:i]+=2)i=*S-*s;for(i=0;i<n/2;)printf("%d\n",v[++i]);}}

C++: #include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        set<int> remains;
        for (int i = 1; i < n; i++) {
            int remain = (i * i) % n;
            remains.insert(remain);
        }
        int max = (n - 1) / 2;
        int* differences = new int [max + 1];
        fill_n(differences, max + 1, 0);
        for (set<int>::iterator it1 = remains.begin(); it1 != remains.end(); it1++) {
            for (set<int>::iterator it2 = it1; it2 != remains.end(); it2++) {
                if (it1 == it2) {
                    continue;
                }
                int diff = *it1 - *it2;
                if (diff < 0) {
                    diff += n;
                }
                if (diff > max) {
                    diff = n - diff;
                }
                differences[diff] += 2;
            }
        }
        for (int i = 1; i <= max; i++) {
            cout << differences[i] << endl;
        }
        delete[] differences;
    }
}

C++: #include <set>
#include <iostream>
int i,n,v[9999];main(){for(;cin>>n,n;){std::set<int>t;for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(std::set<int>::iterator s=t.begin(),S=s,T=t.end();s!=T;S=++s)for(;++S!=T;v[i>n/2?n-i:i]+=2)i=*S-*s;for(i=0;i<n/2;)cout<<v[++i]<<endl;}}