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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[10010];
int b[10010];

int main() {
	int n;
	while(n=in()){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int i,j;
		for(i=1;i<n;i++){
			a[i*i%n]=1;
		}
		for(i=0;i<n;i++){
			if(a[i]==0)continue;
			for(j=i+1;j<n;j++){
				if(a[j]==0)continue;
				int k=i-j;
				if(k<0)k+=n;
				if(k>(n-1)/2)k=n-k;
				b[k]+=2;
			}
		}
		for(i=1;i<(n+1)/2;i++)cout<<b[i]<<endl;
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n,n){
		set<int> table;
		int t[5001] = {0};
		for(int i=1;i<n;i++){
			table.insert((i*i)%n);
		}
		for(set<int>::iterator it = table.begin();it != table.end();++it){
			for(set<int>::iterator it2 = table.begin();it2 != table.end();++it2){
				int delta = (*it) - (*it2);
				if(delta<0)delta+=n;
				if(delta>(n-1)/2)delta=n-delta;
				t[delta]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			cout << t[i] << endl;
		}
	}
}

C++: #include<iostream>
#include<map>
#define MAX 5001
using namespace std;
int main()
{
	while(true){
		int n;
		int c[MAX] = {0,};
		map<int,int> m;
		map<int,int>::iterator itm;

		cin >> n;
		if( n == 0 )break;

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

		itm = m.begin();
		while( itm != m.end() ){
			map<int,int>::iterator itm_t = m.begin();
			while( itm_t != m.end() ){
				if( itm_t != itm ){
					int diff = itm_t->second - itm->second;
					diff = diff < 0 ? diff + n : diff;
					diff = diff > (n-1)/2 ? n - diff : diff;
					++c[ diff ];	
				}
				++itm_t;
			}
			++itm;
		}
		for(int i = 1; i <= (n-1)/2; ++i){
			cout << c[i] << '\n';
		}
	}
	return 0;
}

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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		unordered_set<int>se;
		for (int i = 1; i < n; i++)se.insert(i*i%n);
		map<int, int>mp;
		for (auto i = se.begin(); i != se.end(); i++) {
			for (auto j = se.begin(); j != se.end(); j++) {
				if (i == j)continue;
				int d = *i - *j;
				if (d < 0)d += n;
				if (d > (n - 1) / 2) d -= n;
				mp[abs(d)]++;
			}
		}
		for (auto p : mp)printf("%d\n", p.second);
	}
}

C++: #include <stdio.h>
#include <set>
#include <vector>
using namespace std;
const int N=1e4+10;
#define PB push_back
int abs(int n){return n>0?n:-n;}
int main(){
    int n,a[N],mid,temp;
    set<int> s;
    vector<int> v;
    while(scanf("%d",&n)!=EOF){
        if(n==0)return 0;
        s.clear();
        v.clear();
        for(int i=1;i<n;i++)s.insert((i*i)%n);
        mid=n>>1;
        for(int i=1;i<=mid;i++)a[i]=0;
        for(int i:s)v.PB(i);
        for(int i=0;i<v.size();i++)for(int j=0;j<v.size();j++)if(i!=j){
            temp=abs(v[j]-v[i]);
            if(temp>mid)a[n-temp]++;
            else a[temp]++;
        }
        for(int i=1;i<=mid;i++)printf("%d\n",a[i]*2);
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto& e:c)
#define iter(it,c) for(auto it=c.begin(); it!=c.end(); ++it)

int main(){
    int n;
    while(cin>>n && n){
        vector<int> sq;
        for(int i=1;i<=n/2;i++){
            sq.push_back((i*i)%n);
        }
        sort(all(sq));
        sq.erase(unique(all(sq)),sq.end());
        int ans[5000]={};
        rep(i,sq.size()){
            rep(j,sq.size()){
                int t=sq[i],u=sq[j];
                int x=min(abs(t-u),n-abs(t-u));
                ans[x]++;
            }
        }
        for(int i=1;i<=n/2;i++){
            cout<<ans[i]<<endl;
        }
    }
}

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

using namespace std;

int main() {
  int n;
  while(cin >> n && n) {
    set<int> st;
    map<int, int> cnt;
    for(int i=0; i<n-1; i++) {
      st.insert( (i+1)*(i+1) % n );
    }
    
    int const size = st.size();
    
    vector<int> vec;
    set<int>::iterator it = st.begin();
    for(it; it!=st.end(); it++) vec.push_back(*it);
    
    for(int i=0; i<size; i++) {
      for(int j=0; j<size; j++) {
	if(i == j) continue;
	int temp = vec[i] - vec[j];
	if(temp < 0) { temp += n; }
	if(temp > (n-1)/2) { temp = n - temp; }
	cnt[temp] ++;
      }
    }
    
    for(int i=1; i<=(n-1)/2; i++) {
      cout << cnt[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 i=0;i<n/2;i++){
			std::cout << buf[i] << std::endl;
		}
	}
}

C++: #include<iostream>
#include<map>
#include<vector>
using namespace std;
int t[1000];
int u[1000],us;
int v[1000];
int n,a,size;
int main(){
  while(cin>>n&&n){
    size=(n-1)/2;
    for(int i=0;i<1000;i++)t[i]=u[i]=v[i]=0;
    us=0;

    for(int i=1;i<n;i++){
      a=i*i%n;
      t[a]++;
      if(t[a]==1)u[us++]=a;
    }

    for(int i=0;i<us;i++){
      for(int j=0;j<us;j++){
	if(i==j)continue;
	a=u[i]-u[j];
	if(a<0)a+=n;
	if(a>size)a=n-a;
	v[a]++;
      }
    }
    for(int i=1;i<=size;i++){
      cout<<v[i]<<endl;
    }
  }
  return 0;
}

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

int main() {
    int n;
    while (cin >> n, n) {
        int m = (n-1)/2;
        vector<int> v;
        for (int i=1; i<n; ++i) {
            v.push_back((i*i) % n);
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        vector<int> cnt(m+1, 0);
        for (int i=0; i<(int)v.size(); ++i) {
            for (int j=0; j<(int)v.size(); ++j) {
                int sub = v[i] - v[j];
                if (sub < 0) sub += n;
                if (m < sub) sub = n - sub;
                cnt[sub] ++;
            }
        }
        for (int i=1; i<=m; ++i) {
            cout << cnt[i] << endl;
        }
    }
    return 0;
}