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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

map<int,int> data;

int f(int tmp,int n){
    if( data.find(tmp)!=data.end() )return data[tmp];
    int pre = tmp;
    while(1){
        bool f=true;
        if(tmp<0)tmp+=n,f=false;
        if(tmp>(n-1)/2)tmp = n-tmp,f=false;
        if(f)break;
    }
    data[pre] = tmp;
    return tmp;
}

int main(){
    int n;
    while(cin>>n&&n){
        set<int> a;
        for(int i=1;i<n;i++){
            a.insert( (i*i)%n );
        }
        
        vector<int> vec;
        for(int x : a) vec.pb(x);
        map<int,int> b;

        rep(i,vec.size()){
            rep(j,vec.size()){
                if(i==j)continue;
                int tmp = vec[i]-vec[j];
                tmp = f(tmp,n);
                b[tmp]++;
            }
        }
        for(pii x : b){
            printf("%d\n",x.second);
        }
    }
}

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

int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		int *n_num = new int[n];
		bool *is_n = new bool[n];
		for(int i=0;i<n;i++){
			is_n[i] = false;
		}
		for(int i=1;i<=(n-1)/2;i++){
			is_n[i*i%n] = true;
		}
		int a=0;
		for(int i=0;i<n;i++){
			if(is_n[i] == true){
				n_num[a++] = i;
			}
		}

		int *n_cou = new int[(n-1)/2+1];
		for(int i=1;i<=(n-1)/2;i++){n_cou[i] = 0;}

		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				int n_mem = (n_num[i]-n_num[j])%n;
				int tmp;
				do{
					tmp = n_mem;
					if(n_mem < 0)
						n_mem += n;
					if(n_mem > (n-1)/2)
						n_mem = n - n_mem;
				}while(tmp != n_mem);
				n_cou[n_mem]++;
			}
		}

		for(int i=1;i<=(n-1)/2;i++){
			cout << n_cou[i] << endl;
		}
		delete[] n_num;
		delete[] n_cou;
	}
	return 0;
}

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 n;
	while(scanf("%d", &n), n){
		vi nums;
		nums.reserve(10000);
		reep(i, 1, n)
			nums.push_back((i*i)%n);
		int half = (n-1) / 2;

		sort(nums.begin(), nums.end());
		int size = distance(nums.begin(), unique(nums.begin(), nums.end()));

		vi ans(half+1, 0);
		rep(i, size){
			rep(j, i+1){
				int p = abs(nums[i]-nums[j]);
				if(p>half) p = n - p;
				++ans[p];
			}
		}
		reep(i, 1, half+1)
			printf("%d\n", ans[i]*2);
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define N_MAX 10000
int main()
{
  
  int n, fact[N_MAX + 1];
  set< int > digit;
  map< int , int > mul;

  for(int i = 1; i <= N_MAX; i++){
    fact[i] = i * i;
  }

  while(cin >> n, n){
    for(int i = 1; i< n; i++){
      digit.insert(fact[i] % n);
    }
    for(__typeof digit.begin() it = digit.begin(); it != digit.end(); it++){
      for(__typeof digit.begin() iitt = digit.begin(); iitt != digit.end(); iitt++){
        if(it == iitt) continue;

        int calc = *it - *iitt;
        if(calc < 0) calc += n;
        if((n - 1) / 2 < calc) calc = n - calc;
        mul[calc]++;
      }
    }

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

    mul.clear();
    digit.clear();
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(int n){
  vector <int> num;
  for(ll i=1;i<n;i++)num.push_back(i*i%n);
  sort(num.begin(),num.end());
  num.erase(unique(num.begin(),num.end()),num.end());
  
  int used[10001]={};
  for(int i=0;i<num.size();i++){
    for(int j=0;j<num.size();j++){
      if(i==j)continue;
      int a=num[i]-num[j];
      if(a<0)a+=n;
      if((n-1)/2<a)a=n-a;
      used[a]++;
    }
  }
  for(int i=1;i<(n-1)/2;i++)cout << used[i]<<endl;
}

int main(){
  int n;
  while(cin>>n,n)solve(n);
  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;
		}
	}
}

C++: #include<stdio.h>
bool table[10001];
int now[10001];
int count[10001];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<=10000;i++){
			table[i]=false;
			now[i]=0;
			count[i]=0;
		}
		int index=0;
		for(int i=1;i<a;i++){
			int val=i*i%a;
			if(!table[val]){
				table[val]=true;
				now[index++]=val;
			}
		}
		for(int i=0;i<index;i++){
			for(int j=i+1;j<index;j++){
				int t=now[i]-now[j];
				if(t<0)t+=a;
				if(t>(a-1)/2)t=a-t;
				count[t]++;
			}
		}
		for(int i=1;i<=a/2;i++)printf("%d\n",count[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(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;)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;
	
	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[abs(nums[i]-nums[j])>half?n-abs(nums[i]-nums[j]):abs(nums[i]-nums[j])];
			}
		}
		for(i=1; i<=half; ++i)
			printf("%d\n", ans[i]*2);
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int n;

int main(){
  while(cin >> n ,n){
    int ans[(n-1)/2];
    memset(ans,0,sizeof(ans));
    vector<int> v;
    vector<int> nv;
    int nn = n;

    for(int i = 1 ; i < nn ; i++){      
      v.push_back(i*i%n);
    }
    sort(v.begin(),v.end());
    for(int i = 1 ; i < nn ; i++){ 
      if(v[i] != v[i-1]){ 
	nv.push_back(v[i-1]);
      }       
    }
   
    for(int i = 0 ; i < nv.size(); i++){
      for(int j = 0 ; j < nv.size() ; j++){
	if(i == j) continue;

	int res = nv[i]-nv[j];
	if(res < 0){
	  res += nn;
	}
	if(res > (nn-1)/2){
	  res = nn - res;
	}
	ans[res-1]++;
      }
    }

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

  return 0;
}