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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>
#include <set>


using namespace std;

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        int box[10001]={0};
        
        set<int> se;
        for(int i=1; i<n; i++){
            int ii=i*i % n;
            se.insert(ii);
        }
        
        /*
        for(int i=1; i<=n/2; i++){
            cout<<box[i]<<endl;
        }
        */
        
        // 要素を出力する
        vector<int> a_b;
        set<int>::iterator it = se.begin();
        while( it != se.end() )
        {
            
            //cout << *it << endl;
            a_b.push_back(*it);
            it++;
        }
        
        for(int i=0; i<a_b.size(); i++){
            for(int j=0; j<a_b.size(); j++){
                int ans=abs(a_b[i]-a_b[j]);
                if(ans>n/2)ans=n-ans;
                box[ans]++;
            }
        }
        
        for(int i=1; i<=n/2; i++){
            cout<<box[i]<<endl;
        }
        
        
        
    }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-9
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;
int main(){
	int n;
	while(scanf("%d",&n),n){
		bool flg[12800]={0};
		vector < int > numbers;
		map <int,int> cnt;
		reps(i,1,n){
			if(flg[(i*i)%n]++)continue;
			numbers.PB((i*i)%n);
		}
		int len = numbers.size();
		rep(i,len){
			rep(j,len){
				if(i == j)continue;
				int tmp = numbers[i]-numbers[j];
				if(tmp < 0)tmp += n;
				if(tmp > (n-1)/2)tmp = n-tmp;
				cnt[tmp]++;
			}
		}
		map <int,int> :: iterator it;
		for(it = cnt.begin(); it != cnt.end(); it++){
			cout << it->se << endl;
		}
	}
	return 0;
}

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

#define MAX_N 100000

long long q[MAX_N];
long long x[MAX_N];
long long n;
vector<long long>p;

int main() {
	while (true) {
		for (int i = 0; i < MAX_N; i++) {
			q[i] = 0; x[i] = 0;
		}
		cin >> n;
		p.clear();
		if (n == 0) { break; }
		for (int i = 1; i < n; i++) {
			q[(i*i) % n]++;
		}
		for (int i = 1; i < n; i++) {
			if (q[i] >= 1) {
				p.push_back(i);
			}
		}
		for (int i = 0; i < p.size(); i++) {
			for (int j = 0; j < p.size(); j++) {
				if (i != j) {
					long long z;
					z = abs(n * n + p[i] - p[j]) % n;
					z = min(z, n - z);
					x[z]++;
				}
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++) {
			cout << x[i] << endl;
		}
	}
}

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

using namespace std;

int main()
{
	int n, m, a[5001], p, b[10001], t;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		m = (n-1)/2;
		fill(a, a+m, 0);
		p = 0;
		for(int i = 1; i < n; i++){
			t = (i*i)%n;
			bool f = true;
			for(int j = 0; j < p; j++){
				if(t == b[j]){
					f = false;
					break;
				}
			}
			if(f){
				b[p++] = t;
			}
		}
		
		for(int i = 0; i < p-1; i++){
			for(int j = i+1; j < p; j++){
				t = b[j] - b[i];
				if(t < 0){
					t += n;
				}
				if(t > m){
					t = n - t;
				}
				a[t] += 2;
			}
		}
		for(int i = 1; i <= m; i++){
			cout << a[i] << endl;
		}
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

set<int> app;

main(){
	int n;
	while(scanf("%d",&n)){
		if(n==0)break;
		
		app.clear();
		
		for(int i=1;i<n;i++){
			app.insert(i*i%n);
		}
		vector<int> vapp((n-1)/2);
		for(set<int>::iterator sp=app.begin();sp!=app.end();sp++){
			for(set<int>::iterator tsp=sp;tsp!=app.end();tsp++){
				if(sp==tsp)continue;
				int diff=*tsp-*sp;
				if(diff<0)diff+=n;
				if(diff>(n-1)/2)diff=n-diff;
				vapp[diff-1]+=2;
			}
		}
		for(int i=0;i<vapp.size();i++){
			cout<<vapp[i]<<endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
int main(){
  ll n;
  while(cin >> n,n){
    vector<ll>ve,ans(n/2+1);
    map<ll,ll>mp;
    fill(ans.begin(),ans.end(),0);
    for(int i = 1 ; i*2 < n ; i++ ){
      if(mp[(i*i)%n] == 0)ve.push_back((i*i)%n);
      mp[(i*i)%n] = 1;
    }
    sort(ve.begin(),ve.end());
    vector<ll>::iterator a =  ve.begin(),b;
    for(; a != ve.end() ; a++ ){
      for(b = a; b != ve.end() ; b++ ){
	if(*b == *a)continue;
	if(((*b) - (*a)) > (n-1)/2 ){
	  ans[(n - (*b) + (*a))]+=2;
	} else {
	  ans[(*b) - (*a)]+=2;
	}
      }
    }
    vector<ll>::iterator it =  ans.begin();
    for(; it != ans.end() ; it++)if((*it) != 0)cout << (*it) << 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;
		vector<int> v0;
		vector<int> v1;

		v1.resize((n+1) / 2);
		for(int i = 0; i < v1.size(); i++)
			v1[i] = 0;

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