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 <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const int INF = 1000000;
const int mod = 1e9 + 7;



int main(){
	int n;
	while (/*cin >> n*/scanf("%d",&n) != EOF && n > 0) {
		if(n % 4 == 3) {
			for(int i = 0; i<(n-1)/2; i++) printf("%d\n", (n-1)/2 -1);
			continue;	
		}
		set<int> s;
		map<int, int> m;
		for(int i = 1; i < n; i++) s.insert(i * i % n);
		//for(auto it :s) cout<<it<<endl;
		for(set<int>::iterator it = s.begin(); it != s.end(); ++it){
			//for(set<int>::iterator it2 = s.begin(); it2 != s.end(); it2++){
			set<int>::iterator it2 =it;
			++it2;
			while(it2 != s.end()){
				int a = *it - *it2;
				if(a < 0) a += n;
				if(a > (n - 1) / 2) a = n - a;
				m[a] += 2;
				++it2;
			}
		}
		for(map<int, int>::iterator it = m.begin(); it != m.end(); ++it){
			//cout<</*it->fi<<" "<<*/it->se<<endl;
			printf("%d\n", it->se);
		}
	}
}

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int main() {
	int ans[5002],m[5002],f[5002],n,i,j,k,c;
	while(cin >> n) {
		if (n==0) break;
		c=0;
		for (i=0;i<5003;i++) ans[i]=f[i]=0;
		for (i=1;i<=(n-1)/2;i++) { k=(i*i) % n; if (f[k]==0) { f[k]=1; m[c++]=k; }} 
	for (i=0;i<c-1;i++) 
		 for (j=i+1;j<c;j++) {
          k=m[j]-m[i];
		  k=k<0 ? k+n : k;
		  k=k>(n-1)/2 ? n-k : k;
		  ans[k]++;
		 }
     for (i=1;i<=(n-1)/2;i++) cout << ans[i]*2 << endl;
	}
return 0;
 }

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

int main(void){
	int n;

	while(cin>>n && n){
		/* ツ妥ヲツ暗ェツ段ツ階ツづ個計ツ算 */
		set<int> first;
		for(int i=1;i<n;i++){
			first.insert(i*i%n);
		}

		/* ツ妥ヲツ禿ア,ツ三ツ段ツ階ツづ個計ツ算 */
		int max = (n-1) / 2;
		int count[max+1];
		memset(count,0,sizeof(count));
		for(set<int>::iterator i = first.begin(); i != first.end(); i++){
			for(set<int>::iterator j = first.begin(); j != first.end(); j++){
				if(*i == *j) continue;

				int diff = *i - *j;
				if(diff <= 0) diff += n;
				if(diff > max) diff = n - diff;
				count[diff]++;
			}
		}

		for(int i=1;i<=max;i++){
			cout<<count[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);
			}
		}
		
		sort(v.begin(),v.end());
		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<algorithm>
#include<vector>

using namespace std;

const int MAX = 10005;
const int INF = (1<<20);

int data[MAX],n;


void solve(){
  vector<int> V;
  fill(data,data+MAX,0);
  for(int i = 1; i < n; i++){
    V.push_back((i*i)%n);
  }
  V.push_back(0);
  V.push_back(INF);
  sort(V.begin(),V.end());
  vector<int> VV;
  int now = 0;
  while(1){
    now = *upper_bound(V.begin(),V.end(),now);
    if(now == INF) break;
    VV.push_back(now);
  }
  for(int i = 0; i < VV.size(); i++)
    for(int j = 0; j < VV.size(); j++)
      if(i!=j) {
	int num = VV[i]-VV[j];
	if(num < 0) num += n;
	if(num > (n-1)/2) num = n-num;
	data[num]++;
      }
}

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


int main(){
  while(cin >> n && n){
    solve();
    print();
  }
  return 0;
}

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

int main(){
  int n,cnt[N];
  set<int> s;
  while(1){
    cin>>n;
    if(!n)break;
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<n;i++)s.insert((i*i)%n);
    set<int>::iterator ite,ite2;
    for(ite=s.begin();ite!=s.end();ite++){
      for(ite2=s.begin();ite2!=s.end();ite2++){
	int a=*ite,b=*ite2;
	if(a==b)continue;
	int cal=a-b;
	if(cal<0)cal+=n;
	if(cal>(n-1)/2)cal=n-cal;
	cnt[cal]++;
      }
    }
    for(int i=1;i<=(n-1)/2;i++)cout<<cnt[i]<<endl;
    s.clear();
  }
  return 0;
}

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

int main()
{
  int n;
  vector<int> num(50000);
  set<int> a;
  set<int>::iterator it, itr;
  int i, t;

  while (cin>>n, n) {
    a.clear();
    for (i = 0; i < n; i++) num[i] = 0;
    for (i = 1; i < n; i++) a.insert((i*i)%n);
    for (it = a.begin(); it != a.end(); it++) {
      for (itr = it; itr != a.end(); itr++) {
	t = *it - *itr;
	if (t == 0) continue;
	if (t < 0) t += n;
	if ((n-1)/2 < t) t = n-t;
	num[t] += 2;
      }
    }
    for (i = 1; i <= (n-1)/2; i++)
      cout<<num[i]<<endl;
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		set<int> Set;
		for(int i = 1; i < n; ++i)
		{
			Set.insert((i * i) % n);
		}
		vector<int> Vec;
		for(set<int>::iterator Ite = Set.begin(); Ite != Set.end(); ++Ite)
		{
			Vec.push_back(*Ite);
		}
		map<int, int> Map;
		int size = Vec.size();
		for(int i = 0; i < size; ++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;
				}
				Map[temp]++;
			}
		}
		for(int i = size - 1; i >= 0; --i)
		{
			for(int j = i - 1; j >= 0; --j)
			{
				int temp = Vec[i] - Vec[j];
				if(temp < 0)
				{
					temp += n;
				}
				if(temp > (n - 1) / 2)
				{
					temp = n - temp;
				}
				Map[temp]++;
			}
		}
		for(int i = 1; i <= (n - 1) / 2; ++i)
		{
			cout << Map[i] << endl;
		}	
	}
}

int main()
{
	solve();
	return(0);
}