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 <set>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int ok(int n){
	if(n < 2)return 0;
	for(int i = 2 ; i*i <= n ; i++){
		if(n % i == 0) return 0;
	}
	return 1;
}
int main(){
	int n;
	while(cin >> n,n){
		set<int> r;
		for(int i = 1 ; i < n ; i++) r.insert((i*i)%n);
		vector<int> wow;
		for(set<int>::iterator it = r.begin() ; it != r.end() ; ++it)
			wow.push_back(*it);
		int mp[10001]={0};
		for(int i = 0 ; i < wow.size() ; i++){
			for(int j = 0 ; j < wow.size() ; j++){
				if( i == j) continue;
				int g = wow[i] - wow[j];
				if(g < 0) g += n;
				if(g > (n-1)/2) g = n - g;
				mp[g]++;
			}
		}
		for(int i = 1 ; i <= (n-1)/2 ; i++)
			cout << mp[i] << endl;
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;
 
vector<int> p;
int use[10000];
int ans,n,ansp[10000];
void dfs(int x){
  for(int i=0;i<(int)p.size();i++){
       if(p[x]!=p[i]) ans=p[x]-p[i];
    else continue;
    if(ans<0) ans+=n;
    if(ans>(n-1)/2) ans=n-ans;
    ansp[ans]++;
  }
  if(x+1<(int)p.size())dfs(x+1);
  }
 
int main(){
  while(1){
  cin>>n;
  if(n==0) break;
  int t;
  for(int i=0;i<10000;i++) use[i]=0,ansp[i]=0;
    for(int i=1;i<n;i++)t=(i*i)%n,use[t]=1;
    for(int i=0;i<n;i++) if(use[i]==1) p.push_back(i);
    dfs(0);
    for(int i=1;i<=(n-1)/2;i++) cout<<ansp[i]<<endl;
    p.clear();
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long lli;

lli n;

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 10010;

int main(void){
    int square[MAX];
    for (int i=1; i < MAX+1; i++) square[i-1] = i*i;
    
    while (true){
        int n;
        cin >> n;
        if (n == 0) break;
        int m = (n-1)/2;
        
        int raw_mod[n-1],mod[n-1];
        for(int i = 0; i < n-1; i++) raw_mod[i] = square[i]%n;

        sort(raw_mod,raw_mod+n-1);
        mod[0] = raw_mod[0];
        int size;
        for(int i = 1, j = 1; i < n-1; i++){
            if (mod[j-1] != raw_mod[i]){
                mod[j] = raw_mod[i];
                j++;
            }
            size = j;
        }

        int hist[MAX] = {};
        for (int i = 0; i < size-1; i++)
            for (int j = i+1; j < size; j++){
                
                int tmp1 = mod[i]-mod[j];
                if (tmp1 < 0) tmp1 += n;
                if (tmp1 > m) tmp1 = n-tmp1;
                
                int tmp2 = mod[j]-mod[i];
                if (tmp2 < 0) tmp2 += n;
                if (tmp2 > m) tmp2 = n-tmp2;
                
                hist[tmp1-1] += 1;
                hist[tmp2-1] += 1;
            }

        for(int i = 0; i < size; i++)
            cout << hist[i] << endl;
    }
    return 0;    
}

C++: /*
 * 0142.cpp
 *
 *  Created on: 2011/07/27
 *      Author: isa
 */

#include <iostream>
#include <set>
#include <map>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int n;

	while(cin >> n && n){
		vector<int> v;
		int times[((n-1)/2)+1];

		memset(times,0,sizeof(times));
		for(int i=1;i<n;i++){
			if(find(v.begin(),v.end(),i*i%n) == v.end()){
				v.push_back(i*i%n);
			}
		}

		for(int i=0;i<v.size();i++){
			for(int j=0;j<v.size();j++){
				int tmp;
				if(i == j) continue;
				tmp = v[i] - v[j];
				if(tmp < 0) tmp+=n;
				if(tmp > (n-1)/2) tmp = n - tmp;
				times[tmp]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			cout << times[i] << endl;
		}

	}
}

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

#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 a[5000];
		memset(a,0,sizeof(a));
		
		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);
			}
		}

		rep(i,v.size())
		{
			REP(j,i+1,v.size())
			{
				int ans = v[i] - v[j];
				if(ans < 0) ans += n;
				if(ans > n2) ans = n - ans;
				a[ans]++;
			}
		}
		
		REP(i,1,n2+1)
		{
			cout << a[i]*2 << endl;
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(i*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();i++){
            for(int j=0,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]<<endl;
    }
}

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

int mp[10000];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		memset(mp, 0, sizeof(mp));
		unordered_set<int>se;
		for (int i = 1; i < n; i++)se.insert(i*i%n);
		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 (int i = 1; i <= (n - 1) / 2; i++)printf("%d\n", mp[i]);
	}
}

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

using namespace std;

const int MAX = 10000;
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(VV[i]!=VV[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;
}