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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
 
#define reep(i,a,b) for(long long i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
 
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
    v.assign(a,vector<T>(b,t));
}
 
//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	ll n;
	while(cin>>n,n){
		vector<ll> v(n-1);
		vector<ll> x((n-1)/2);
		for(ll i=0;i<n-1;i++){
			v[i]=((i+1)*(i+1))%n;
			// cout<<i<<" "<<v[i]<<endl;
		}
		sort(ALL(v));
		v.erase(unique(ALL(v)),v.end());
		rep(i,v.size()){
			// cout<<v[i]<<endl;
			rep(j,v.size()){
				if(i==j) continue;
				ll a=v[i]-v[j];
				if(a<0) a+=n;
				if(a>(n-1)/2) a=n-a;
				x[a-1]++;
			}
		}
		rep(i,x.size()){
			cout<<x[i]<<endl;
		}
		// cout<<endl;
	}
}

C++: #include <cstdio>
#include <cstring>

int n;
int cnt[10001],cnt2[10001];;

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(cnt,0,sizeof(cnt));
		memset(cnt2,0,sizeof(cnt2));
		for(int i=1;i<n;i++){
			cnt[i*i%n]++;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j)continue;
				if(cnt[i]>0 && cnt[j]>0){
					int a=i-j;
					if(a<0)a+=n;
					if(a>(n-1)/2)a=n-a;
					cnt2[a]++;
				}
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			printf("%d\n",cnt2[i]);
		}
	}
	return 0;
}

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

using namespace std;

int func(int s, int m, int n)
{
	if(0 < s && s <= m){
		return s;
	}
	if(0 > s){
		return func(s+n, m, n);
	}
	return func(n-s, m, n);;
}

int main()
{
	int n, m, a[10001];
	
	while(cin>>n&&n){
		set<int> st;
		vector<int> vec;
		fill(a, a+10001, 0);
		
		for(int i = 1; i < n; i++){
			st.insert((i*i)%n);
		}
		set<int>::iterator it = st.begin();
		while(it != st.end()){
			vec.push_back(*it);
			it++;
		}
		
		m = (n-1)/2;
		for(int i = 0; i < vec.size(); i++){
			for(int j = i+1; j < vec.size(); j++){
				a[func(vec[i]-vec[j], m, n)]++;
				a[func(vec[j]-vec[i], m, n)]++;
			}
		}
		
		for(int i = 1; i <= m; i++){
			cout << a[i] << endl;
		}
	}
	
	return 0;
}

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

using namespace std;

int main() {
  int n;
  while(cin >> n && n) {
    set<int> st;
    int cnt[5000] = {};
    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-1; i++) {
      for(int j=i+1; j<size; j++) {
	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]*2 << 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, z;
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 = i + 1; j < p.size(); j++)
			{
				if (i != j)
				{
					z = p[i] - p[j];
					if (z < 0) { z += n; }
					if (z > (n - 1) / 2) { z = n - z; }
					x[z]++;
				}
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++)
		{
			cout << x[i] * 2 << endl;
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int d[10001]={0};
int f[10001]={0};

int main(){
	int n;
	while(cin>>n,n){
		vector<int>V;
		memset(d,0,sizeof(d));
		memset(f,0,sizeof(f));
		
		for(int i=1;i<n;i++){
			int t=i*i%n;
			if(f[t]==0){
				f[t]=1;
				V.push_back(t);
			}
		}
		
		
		for(int i=0;i<V.size();i++){
			for(int j=i+1;j<V.size();j++){
				int t=V[i]-V[j];
				if(t<0)t+=n;
				if(t>(n-1)/2)t=n-t;
				d[t]+=2;
			}
		}
		
		for(int i=1;i<=(n-1)/2;i++){
			cout<<d[i]<<endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <map>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	double n2;
		
	while(cin >> n && n)
	{
		int res = n;
		int count = 0;

		while(res != 0)
		{
			if(res%10 == 0)
			{
				count++;
			}
			res /= 10;
		}
		
		if(count == 1) break;


		n2 = (n-1)/2;
		vector<int> v;
		REP(i,1,n)
		{
			int temp = i*i;
			temp %= n;
			
			vector<int>::iterator ite = find(v.begin(),v.end(),temp);
			if(ite == v.end())
			{
				v.push_back(temp);
			}
		}
		
		map<int,int> m;
		rep(i,v.size())
		{
			rep(j,v.size())
			{
				if(i != j)
				{

					int ans = v[i] - v[j];
				
					if(ans < 0) ans += n;
					if(ans > n2) ans = n - ans;

					m[ans]++;
				}
			}
		}

		REP(i,1,n2+1)
		{
			cout << m[i] << endl;
		}
	}

	return 0;
}

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    set<int> mod;
    for (int i = 1; i < n; ++i)
      mod.insert((i*i)%n);

    vector<int> ans(n, 0);
    for (set<int>::iterator it = mod.begin(); it != mod.end(); ++it) {
      for (set<int>::iterator jt = it; jt != mod.end(); ++jt) {
	if (*it == *jt)
	  continue;
	int diff = *it - *jt;
	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]*2 << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	
	int n, a[20000];
	
	bool exist[20000];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i <= n; i++){
			exist[i] = false;
			a[i] = 0;
		}
		
		for(int i = 1; i < n; i++){
			exist[(i * i) % n] = true;
		}
		
		int dummy;
		
		for(int i = 1; i < n; i++){
			for(int j = 1; j < n; j++){
				if(i == j){
					continue;
				}
				if(exist[i] && exist[j]){
					dummy = i - j;
					if(dummy < 0){
						dummy += n;
					}
					if(dummy > (n - 1) / 2){
						dummy = n - dummy;
					}
					a[dummy]++;
				}
			}
		}
		
		for(int i = 1; i <= n / 2; i++){
			printf("%d\n", a[i]);
		}
	}
	
	return 0;
}