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 <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,size;
        int raw_mod[MAX],mod[MAX],hist[MAX] = {};
        
        cin >> n;
        if (n == 0) break;
        int m = (n-1)/2;
        
        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];
        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;
        }

        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++: #include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <iterator>
using namespace std;

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    unordered_set<int> sqmod;
    for(int i = 1; i < N; ++i)
      sqmod.insert((i*i)%N);
    // sort(begin(sqmod), end(sqmod));
    // sqmod.erase(unique(begin(sqmod), end(sqmod)), end(sqmod));
    vector<int> cnt((N - 1) / 2 + 1, 0);
    for(int i : sqmod) {
      for(int j : sqmod) {
        if(i == j) continue;
        int diff = i - j;
        if(diff < 0) diff += N;
        if(diff > (N - 1)/2) diff = N - diff;
        cnt[diff]++;
      }
    }
    for(int i = 1; i < (int)cnt.size(); ++i) {
      cout << cnt[i] << endl;
    }
  }
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n;
	vector<int> v;
	cin >> n;
	if(n==0) break;
	FOR(i,1,n){
	    v.PB((i*i)%n);
	}
	sort(ALL(v));
	v.erase(unique(ALL(v)),v.end());
	vector<int> ans((n/2));
	REP(i,v.size())FOR(j,i+1,v.size()){
	    int m = v[i] - v[j];
	    if(m < 0) m += n;
	    if(m > (n-1)/2) m = n - m;
	    ans[m-1]++;
	}
	REP(i,ans.size()) cout << 2*ans[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[5000]={};
        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 <iostream>
#include <set>

using namespace std;


int main(void)
{
	int n;
	set<int> target;
	int data[10000];

	while( cin >> n && n != 0 ){
		target.clear();
		for( int i = 0;i < 10000;i++ ) data[i] = 0;
		for( int i = 1;i < n;i++ ){
			target.insert( i * i % n );
		}

		for( set<int>::iterator it = target.begin();it != target.end();it++ ){
			set<int>::iterator it2 = target.begin();
			for(;it2 != target.end();it2++ ){
				int answer = *it - *it2;
				while( 1 ){
					if( answer < 0 ){ answer += n; continue; }
					else if( answer > ( n - 1 ) / 2 ){ answer = n - answer; continue; }
					data[answer]++;
					break;
				}
			}
		}

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

	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int nums[10000];
	int n, size, half;
	while(scanf("%d", &n), n){
		size = 0;
		half = (n-1) / 2;
		reep(i, 1, n)
			nums[size++] = (i*i) % n;

		sort(nums, nums + size);
		size = distance(nums, unique(nums, nums + size));

		vi ans(half+1, 0);
		rep(i, size){
			rep(j, i+1){
				int p = abs(nums[i]-nums[j]);
				if(p>half) p = n - p;
				++ans[p];
			}
		}
		reep(i, 1, half+1)
			printf("%d\n", ans[i]*2);
	}

	return 0;
}

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

#define MAX_N 100000

int q[MAX_N];
int x[MAX_N];
int n;
vector<int>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++) {
				int z;
				z = abs(n + p[i] - p[j]) % n;
				if (z > n / 2) { z = n - z; }
				x[z]++;
			}
		}
		for (int i = 1; i <= n / 2; i++) {
			cout << x[i] << endl;
		}
	}
}

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] = 1;
		}
		for (int i = 0; i < MAX_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 <bits/stdc++.h>
using namespace std;

void solve(int 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 used[10001]={};
  for(int i=0;i<num.size();i++){
    for(int j=0;j<num.size();j++){
      if(num[i]==num[j])continue;
      int a=num[i]-num[j];
      if(a<0)a+=n;
      if((n-1)/2<a)a=n-a;
      used[a]++;
    }
  }
  for(int i=1;i<(n-1)/2;i++)cout << used[i]<<endl;
}

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