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

C++: #include <vector>
#include <cstring>
#include <iostream>
using namespace std;
int n, c, a[10000], v[10000]; bool p[10000], prime[10000];
int main() {
	for(int i = 2; i < 10000; i++) prime[i] = true;
	for(int i = 2; i * i < 10000; i++) {
		if(!prime[i]) continue;
		for(int j = i * i; j < 10000; j += i) prime[j] = false;
	}
	while(scanf("%d", &n), c = 0, n) {
		if(prime[n] && n % 4 == 3) {
			for(int i = 0; i < n / 2; i++) printf("%d\n", (n - 3) / 2);
			continue;
		}
		vector<int> v;
		for(int i = 0; i < n; i++) a[i] = 0, p[i] = false;
		for(int i = 1; i < n; i++) p[i * i % n] = true;
		for(int i = 0; i < n; i++) {
			if(p[i]) v[c++] = i;
		}
		for(int i = 0; i < c; i++) {
			for(int j = i + 1; j < c; j++) {
				int r = v[j] - v[i];
				if(r < 0) r += n;
				if(r > n / 2) r = n - r;
				a[r - 1]++;
			}
		}
		for(int i = 0; i < n / 2; i++) printf("%d\n", a[i] * 2);
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 10001;

int main(void){
    int square[MAX];
    for (int i=1; i < MAX+1; i++) square[i-1] = i*i;
    
    while (true){
        int n;
        cin >> n;
        if (n == 0) break;
        int m = (n-1)/2;
        
        int raw_mod[n-1],mod[m];
        for(int i = 0; i < n-1; i++) raw_mod[i] = square[i]%n;

        sort(raw_mod,raw_mod+n-1);
        mod[0] = raw_mod[0];
        int size;
        for(int i = 1, j = 1; i < n-1; i++){
            if (mod[j-1] != raw_mod[i]){
                mod[j] = raw_mod[i];
                j++;
            }
            size = j;
        }

        int hist[MAX] = {};
        for (int i = 0; i < size-1; i++)
            for (int j = i+1; j < size; j++){
                int tmp1 = mod[i]-mod[j];
                if (tmp1 < 0) tmp1 += n;
                if (tmp1 > m) tmp1 = n-tmp1;
                int tmp2 = mod[j]-mod[i];
                if (tmp2 < 0) tmp2 += n;
                if (tmp2 > m) tmp2 = n-tmp2;
                hist[tmp1-1] += 1;
                hist[tmp2-1] += 1;
            }

        for(int i = 0; i < m; i++)
            cout << hist[i] << endl;
    }
    return 0;    
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	while(cin >> n, n) {
		int a[10000]={};
		int c[5000]={};
		rep2(i,1,n) {
			a[(i*i)%n]++;
		}
		vector<int> v;
		rep2(i,1,n) {
			if(a[i]!=0) v.push_back(i);
		}
		rep(i,v.size()) {
			rep(j,v.size()) {
				if(i==j) continue;
				int s = v[i]-v[j];
				if(s<0) s+=n;
				if(s>(n-1)/2) c[n-s]++;
				else c[s]++;
			}
		}
		rep2(i,1,(n+1)/2) {
			cout << c[i] << endl;
		}
	}
	return 0;
}

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

int main() {
	int n;

	while(cin >> n, n) {
		set<int> s;
		map<int,int> m;
		vector<int> v;

		for(int i = 1; i < n; i++) {
			s.insert(i*i % n);
		}
		for(set<int>::iterator iter = s.begin(); iter != s.end(); iter++) {
			v.push_back(*iter);
		}
		for(int i = 0; i < v.size(); i++) {
			for(int j = 0; j < v.size(); j++) {
				if(i != j) {
					int tmp = (v[i] - v[j] + n) % n;
					if(tmp > (n - 1) / 2) {
						tmp = n - tmp;
					}
					m[tmp]++;
				}
			}
		}
		for(int i = 1; i < (n + 1) / 2; i++)
			cout << m[i]<< endl;
	}
}

C++: #include<iostream>
#include<sstream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
  int n;
  for(;cin>>n,n;)
    {

      map<int,bool>hash;
      vector<int> data;
      for(int i=1;i<n;i++)
	{
	  if(hash.count(i*i%n)==0)
	    {
	      hash[i*i%n]=true;
	      data.push_back(i*i%n);
	    }
	}
      int ans[(n-1)/2+2];
      memset(ans,0,sizeof(ans));
      for(int i=0;i<data.size()-1;i++)
	for(int j=i+1;j<data.size();j++)
	  {
	    int tmp=data[i]-data[j];
	    if(tmp<0)
	      tmp+=n;
	    if(tmp>(n-1)/2)
	      tmp=n-tmp;
	    ans[tmp]++;

	    tmp=data[j]-data[i];
	    if(tmp<0)
	      tmp+=n;
	    if(tmp>(n-1)/2)
	      tmp=n-tmp;
	    ans[tmp]++;
	  }
      for(int i=1;i<=(n-1)/2;i++)
	cout<<ans[i]<<endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n, a[20000];
	
	bool exist[20000];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i <= n; i++){
			exist[i] = false;
			a[i] = 0;
		}
		
		for(int i = 1; i < n; i++){
			exist[(i * i) % n] = true;
		}
		
		int dummy;
		
		for(int i = 1; i < n; i++){
			for(int j = 1; j < n; j++){
				if(i == j){
					continue;
				}
				if(exist[i] && exist[j]){
					dummy = i - j;
					if(dummy < 0){
						dummy += n;
					}
					if(dummy > (n - 1) / 2){
						dummy = n - dummy;
					}
					a[dummy]++;
				}
			}
		}
		
		for(int i = 1; i <= n / 2; i++){
			printf("%d\n", a[i]);
		}
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
	int n;
	while (cin >> n, n) {
		set<int> st;
		rep(i, 1, n) {
			int tmp = i * i % n;
			if (!st.count(tmp)) {
				st.insert(tmp);
			}
		}
		vi d(n / 2 + 1, 0);
		for (auto i = st.begin(); i != st.end(); i++) {
			for (auto j = st.begin(); j != st.end(); j++) {
				int tmp = abs(*i - *j);
				if (tmp > n / 2) {
					tmp = n - tmp;
				}
				d[tmp]++;
			}
		}
		rep(i, 1, n / 2 + 1) {
			cout << d[i] << endl;
		}
	}
}