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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,int> P;

static const double eps = 10e-9;

int main(){
	int n;

	while(~scanf("%d",&n)){
		if(n==0) break;

		vector<int> input;
		for(int i=1;i<=n-1;i++){
			input.push_back((i*i)%n);
		}

		int* table = new int[(n-1)/2+1]();
		//set<int> table;

		sort(input.begin(),input.end());

		vector<int>::iterator end_it = unique(input.begin(),input.end());
		input.erase(end_it,input.end());

		for(int i=0;i<input.size();i++){
			for(int j=0;j<input.size();j++){
				if(i==j) continue;
				int calc = input[i]-input[j] ;
				if(calc < 0) calc+=n;
				if(calc > (n-1)/2) calc = n - calc;

				//table.insert(calc);
				table[calc]++;
			}
		}

		for(int i=1;i<(n-1)/2+1;i++){
			printf("%d\n",table[i]);
		}

		delete[] table;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int number[10001];
    for(int i=1;i<10000;i++)number[i]=i*i;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(number[i]%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[5000]={};
        for(int i=0;i<num.size();i++){
            for(int j=0,k;j<num.size();j++){
                k=num[i]-num[j];
                if(k<0)k+=n;
                if(k>n/2)k=n-k;
                ans[k]++;
            }
        }
        for(int i=1;i<=n/2;i++)cout<<ans[i]<<endl;
    }
}

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

int main(){
    while(1){
        int n;
        cin >> n;

        if(n == 0)  break;

        bool appear[n+1] = {};
        for(int i = 1; i < n; i++){
            appear[(i*i)%n] = true;
        }

        vector<int> p;
        for(int i = 0; i <= n; i++){
            if(appear[i])   p.push_back(i);
        }

        int len = p.size();
        int ans[(n-1)/2 + 1] = {};

        for(int i = 0; i < len; i++){
            for(int j = 0; j < len; j++){
                if(i == j)  continue;
                int diff = p[i] - p[j];
                if(diff < 0)        diff += n;
                if(diff > (n-1)/2)  diff = n - diff;
                ans[diff]++;
            }
        }

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

    return 0;
}

C++: #include <set>
#include <cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;for(i=0;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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

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<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		map<int,bool>tmp;
		loop(i,1,n){
			int t=i*i;
			t%=n;
			tmp[t]=true;
		}
		vi in;
		for(map<int,bool>::iterator it=tmp.begin();it!=tmp.end();it++)
			in.pb(it->first);
		//cout<<in.size()<<endl;
		vi out((n-1)/2+1,0);
		rep(i,in.size())rep(j,in.size())if(i!=j){
			int t=in[i]-in[j];
			t=abs(t);
			if(t>(n-1)/2)t=n-t;
			//if(t<0)t+=n;
			out[t]++;
		}
		loop(i,1,(n-1)/2+1)cout<<out[i]<<endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
  int n;
  while(cin >> n, n){
    int m = (n-1) / 2;
    bool sq[10001] = {false};
    int a[5001] = {0};
    for(int i = 1; i < n; i++) sq[(i*i)%n] = true;
    for(int i = 1; i < n; i++){
      if(!sq[i]) continue;
      for(int j = 1; j < n; j++){
	if(i == j) continue;
	if(!sq[j]) continue;
	int d = i - j;
	if(d < 0){
	  if(d + n > m) a[n-(d+n)]++;
	  else a[d+n]++;
	} else {
	  if(d > m) a[n-d]++;
	  else a[d]++;
	}
      }
    }
    for(int i = 1; i <= m; i++) cout << a[i] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
long n,m,i,j,a[10000],b[5000]={0},d;
while(cin>>n){
if(n==0)break;
for(i=0;i<(n-1)/2;i++)b[i]=0;
for(i=0;i<(n-1)/2;i++)a[i]=((i+1)*(i+1))%n;
sort(a,a+(n-1)/2);
b[0]=a[0];j=1;
for(i=1;i<(n-1)/2;i++){
if(a[i]!=b[j-1]){b[j]=a[i];j++;}
}
m=j;
for(i=0;i<m;i++)a[i]=b[i];
for(i=0;i<(n-1)/2;i++)b[i]=0;
for(i=0;i<m;i++){
for(j=0;j<m;j++){
if(i!=j){
d=a[i]-a[j];
if(d<0)d+=n;
if(d>(n-1)/2)d=n-d;
b[d-1]++;
}
}
}
for(i=0;i<(n-1)/2;i++)cout<<b[i]<<endl;
}
return 0;
}

C++: #include <iostream>
#include <vector>
#include <set>

int f(int n,int a,int b){
	int t = a-b;
	if(t<0)t+=n;
	if(t > n/2){
		return n-t;
	}else{
		return t;
	}
}

int main(){
	int n;
	while(true){
		std::cin >> n;
		if(n==0)break;
		std::set<int> nums;
		for(int i=1;i<n;i++){
			nums.insert((i*i)%n);
		}
		std::vector<int> buf(n/2,0);
		for(int a : nums){
			for(int b : nums){
				if(a!=b)buf[f(n,a,b)-1]++;
			}
		}
		for(int x : buf){
			std::cout << x << std::endl;
		}
	}
}