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 <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	int nums[16384], ans[8192];
	int i, j, n, size, half, p;
	
	while(scanf("%d", &n), n){
		size = 0;
		half = (n-1) / 2;
		for(i=1; i<n; ++i)
			nums[size++] = (i*i) % n;

		sort(nums, nums + size);
		size = unique(nums, nums + size) - nums;

		memset(ans, 0, (half+1)*4);
		for(i=0; i<size; ++i){
			for(j=0; j<i; ++j){
				++ans[(p=abs(nums[i]-nums[j]))>half?n-p:p];
			}
		}
		for(i=1; i<=half; ++i)
			printf("%d\n", ans[i]*2);
	}

	return 0;
}

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

int main(){
	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
		
		long num[10000];
		int ct=0;
		
		for(int i=1; i<n; ++i){
			long p=(i*i)%n;	
			
			bool newin=true;
			for(int j=0; j<ct; ++j){
				if(num[j]==p){
					newin=false;
					break;
				}
			}
			if(newin) num[ct++]=p;
		}
		
		int count[5000];
		for(int i=0; i<5000; ++i) count[i]=0;
		
		for(int i=0; i<ct; ++i){
			for(int j=0; j<ct; ++j){	
				long tmp=num[i]-num[j];
				if(tmp<0) tmp+=n;
				if(tmp>(n-1)/2) tmp=n-tmp;
				
				count[tmp]++;
			}
		}
	
		for(int i=1; i<=(n-1)/2; ++i) printf("%d\n", count[i]);
	}
}

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[n-1];
        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 <set>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;
int number[5000];

void solve()
{
	int n;
	while(cin >> n, n)
	{
		memset(number, 0, sizeof(number));
		set<int> Set;
		for(int i = 1; i < n; ++i)
		{
			Set.insert((i * i) % n);
		}
		vector<int> num;
		int size = (n - 1) / 2;
		set<int>::iterator it = Set.begin();
		while(it != Set.end())
		{
			set<int>::iterator it2 = Set.begin();
			while(it2 != Set.end())
			{
				int temp = *it2 - *it;
				if(temp < 0)
				{
					temp += n;
				}
				if(temp > size)
				{
					temp = n - temp;
				}
				++number[temp];
				++it2;
			}
			++it;
		}
		for(int i = 1; i <= size; ++i)
		{
			cout << number[i] << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

int n;
int* cnt, *use;
int p;
map<int,bool> memo;

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		memo.clear();
		p=0;
		cnt = new int[(n+1)/2];
		use = new int[n];

		for(int i=1; i<n; i++){
			int tmp = i*i%n;
			if(memo[tmp])
				continue;
			memo[tmp] = true;
			use[p++] = tmp;
		}

		for(int i=0; i<p-1; i++){
			for(int k=i+1; k<p; k++){
				int tmp = use[i]-use[k];
				if(tmp<0)
					tmp += n;
				if(tmp>(n-1)/2)
					tmp = n-tmp;
				cnt[tmp] ++;
				tmp = use[k]-use[i];
				if(tmp<0)
					tmp += n;
				if(tmp>(n-1)/2)
					tmp = n-tmp;
				cnt[tmp] ++;
			}
		}

		for(int i=1; i<(n+1)/2; i++)
			cout << cnt[i] << endl;
	}
}

C++: #include <vector>
#include <cstring>
#include <iostream>
using namespace std;
int n, a[10000]; bool p[10000];
int main() {
	while(scanf("%d", &n), n) {
		vector<int> v;
		memset(a, 0, sizeof(a));
		memset(p, 0, sizeof(p));
		for(int i = 1; i < n; i++) p[i * i % n] = true;
		for(int i = 0; i < n; i++) {
			if(p[i]) v.push_back(i);
		}
		for(int i = 0; i < v.size(); i++) {
			for(int j = i + 1; j < v.size(); 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<set>
#include<cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(auto 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;)printf("%d\n",v[++i]);}}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main() {
	int ans[5001],m[5001],f[5001],n,i,j,k,c;
	while(cin >> n) {
		if (n==0) break;
		c=0;
		for (i=0;i<5001;i++) ans[i]=f[i]=0;
		for (i=1;i<=(n-1)/2;i++) { k=(i*i) % n; if (f[k]==0) { f[k]=1; m[c++]=k; }} 
	for (i=0;i<c-1;i++) 
		 for (j=i+1;j<c;j++) {
          k=m[j]-m[i];
		  k=k<0 ? k+n : k;
		  k=k>(n-1)/2 ? n-k : k;
		  ans[k]++;
		 }
     for (i=1;i<=(n-1)/2;i++) cout << ans[i]*2 << endl;
	}
return 0;
 }

C++: #include <set>
#include <cstdio>
#include <cstring>
int i,n,v[9999];
main(){for(;scanf("%d",&n),n;){
	std::set<int>t;
	for(memset(v,0,sizeof(v)),i=1;i<n;i++)t.insert(i*i%n);
	std::set<int>::iterator s,S;
	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=1;i<=n/2;i++)printf("%d\n",v[i]);
}}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        vector<int> v(n - 1, 0);
        REP(i, 0, n - 1) {
            v[i] = ((i + 1) * (i + 1)) % n;
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        vector<int> m(n, 0);
        REP(i, 0, v.size()) {
            REP(j, 0, v.size()) {
                if (i == j) continue;
                int diff = v[i] - v[j];
                if (diff < 0) {
                    diff += n;
                }
                if ((n - 1) / 2 < diff) {
                    diff = n - diff;
                }
                m[diff] += 1;
            }
        }
        REP(i, 1, (n - 1) / 2 + 1) {
            cout << m[i] << endl;
        }
    }
    return 0;
}