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++: /*
 * 0142.cpp
 *
 *  Created on: 2011/07/27
 *      Author: isa
 */

#include <iostream>
#include <set>
#include <map>

using namespace std;

int main(void){
	int n;

	while(cin >> n && n){
		set<int> s;
		map<int,int> m;
		for(int i=1;i<n;i++){
			s.insert((i*i)%n);
			//cout << i*i%n << endl;
		}

		set<int>::iterator it,jt;

		for(it = s.begin(); it != s.end(); ++it){
			for(jt = s.begin(); jt != s.end(); ++jt){
				int tmp;
				if(it == jt) continue;
				tmp = *it - *jt;
				if(tmp < 0) tmp+=n;
				if(tmp > (n-1)/2) tmp = n - tmp;
				m[tmp]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			cout << m[i] << endl;
		}

	}
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		bool isAppeared[10001];
		int data[10001];
		fill(isAppeared,isAppeared+10001,false);
		fill(data,data+10001,0);
		//memset(isAppeared,0,sizeof(isAppeared));
		//memset(data,0,sizeof(data));
		for(int i = 1; i < n; i++){
			int r=(i*i)%n;
			isAppeared[r]=true;
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(isAppeared[i]&&isAppeared[j]){
					int ret=i-j;
					if(ret<0)
						ret+=n;
					if(((n-1)/2)<ret){
						ret=n-ret;
					}
					data[ret]++;
				}
			}
		}
		for(int i = 1; i <= ((n-1)/2); i++){
			if(data[i]!=0)
				cout<<data[i]<<endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin >> n, n) {
    set<int> se;
    
    REP(i,n-1){
      se.insert((i+1)*(i+1)%n);
    }
    vector<int> v((n-1)/2);
    FOR(it1,se) {
      for(set<int>::iterator it2 = it1; it2!=se.end(); it2++) {
        if (*it1==*it2) continue;
        int temp = abs(*it1-*it2);
        if (temp > (n-1)/2) temp = n-temp;
        v[temp-1]++;
      }
    }
    
    FOR(it,v) {
      cout << *it*2 << endl;
    }
  }
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int n;
int dist(int a,int b)
{
	int t=a-b;
	if(t<0)t+=n;
	if(t>(n-1)/2)t=n-t;
	return t;
}
int main()
{
	while(1)
	{
		set<int> s;
		map<int,int> m;
		cin >> n;
		if(n==0)break;
		for(int i=1;i<n;i++)
		{
			int k=i*i;
			s.insert(k%n);
		}
		set<int>::iterator it;
		vector<int> v;
		for(it=s.begin();it!=s.end();it++)v.pb(*it);
		for(int i=0;i<v.size();i++)
		{
			for(int j=0;j<v.size();j++)
			{
				if(i==j)continue;
				int d = dist(v[i],v[j]);
				m[d]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++)cout << m[i] << endl;
	}
	return 0;
}

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[10001]={};
        for(int i=0;i<num.size()-1;i++){
            for(int j=i+1,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]*2<<endl;
    }
}

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<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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

//MLE
int n;
vector<int> v1, v2;

int main(){
	while (cin >> n&&n){
		FOR(i, 1, n){
			int k = i*i % n;
			v1.push_back(k);
		}
		sort(ALL(v1));
		v1.erase(unique(ALL(v1)), v1.end());
		//REP(i, v1.size())cout << v1[i] << " ";
		REP(i, v1.size()){
			REP(j, v1.size()){
				if (i != j){
					int k = v1[i] - v1[j];
					if (k < 0)k += n;
					if (k >(n - 1) / 2)k = n - k;
					v2.push_back(k);
				}
			}
		}
		sort(ALL(v2));
		FOR(i, 1, (n - 1) / 2 + 1){
			cout << upper_bound(ALL(v2), i) - lower_bound(ALL(v2), i) << endl;
		}
		v1.clear();
		v2.clear();
	}
}