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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int nums[10000];
int nums2[10000];

int main(){
	int n;
	while(cin >> n && n){
		memset(nums, 0, sizeof(nums));
		memset(nums2, 0, sizeof(nums2));
		rep(i, n-1){
			nums[((i+1)*(i+1))%n]++;
		}
		for(int i = 1; i < n; i++){
			for(int j = 0; j < n - i; j++){
				int n1 = i;
				if(n1 > (n-1)/2) n1 = n - n1;
				if(nums[j] * nums[i+j] > 0){
					nums2[n1]+=2;
				//	cout << j << " " << i + j << endl;
				}
			}
		}
		rep(i, (n-1)/2) cout << nums2[i+1] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(void){
  int n;
  while(cin>>n,n){
    set<int> s;
    for(int i=1;i<n;++i){
      s.insert((i*i)%n);
    }
    vector<int> v(s.size());
    int p=0;
    for(set<int>::iterator it=s.begin();it!=s.end();++it)v[p++]=*it;
    vector<int> hist((n-1)/2+1);
    for(int i=0;i<v.size();++i){
      for(int j=v.size()-1;j>i;--j){
        int d=v[i]-v[j];
        //cerr<<v[i]<<" "<<v[j]<<endl;
        d=(d<0)?d+n:d;
        d=(d>(n-1)/2)?n-d:d;
        ++hist[d];
      }
    }
    for(int i=1;i<=(n-1)/2;++i){
      cout<<hist[i]*2<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

bool use[10000];
int res[10000];
int cal[10000];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    if(!n)break;

    int ma = (n - 1) / 2, hd = 0;
    rep(i, n)use[i] = false;
    rep(i, n)res[i] = 0;

    rep1(i, n){
      int x = (i * i) % n;
      use[x] = true;
    }
    rep1(i, n)if(use[i])cal[hd++] = i;

    rep(i, hd)rep(j, hd)if(i != j){
      int tmp = cal[j] - cal[i];
      if(tmp < 0)tmp += n;
      if(tmp > ma)tmp = n - tmp;
      ++res[tmp - 1];
    }
    rep(i, ma)printf("%d\n", res[i]);

//*/

//*/ break;
  }
  return 0;
}

C++: #include <stdio.h>
#include <set>
#include <vector>
using namespace std;
const int N=1e4+10;
#define PB push_back
int main(){
    int n,a[N],mid;
    set<int> s;
    vector<int> v;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        s.clear();
        v.clear();
        for(int i=1;i<n;i++)s.insert((i*i)%n);
        mid=n>>1;
        for(int i=0;i<=mid;i++)a[i]=0;
        for(int i:s)v.PB(i);
        for(int i=0;i<v.size();i++)for(int j=0;j<v.size();j++)if(i!=j){
            if(v[j]-v[i]>mid)a[n-(v[j]-v[i])]++;
            else a[v[j]-v[i]]++;
        }
        for(int i=1;i<=mid;i++)printf("%d\n",a[i]*2);
    }
}

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

using namespace std;

struct Info{
	int number;
};


void func(int n){

	int tmp,index = 0,firstCheck[10000],checkTable[10000];
	Info info[10000];

	for(int i = 0; i < 10000; i++)firstCheck[i] = 0;

	for(int i = 1; i <= n-1; i++){
		checkTable[i] = 0;
		tmp = (i*i)%n;

		if(firstCheck[tmp] == 0){
			info[index].number = tmp;
			index++;
			firstCheck[tmp] = 1;
		}
	}

	for(int i = 0; i < index; i++){
		for(int k = 0; k < index; k++){
			if(i != k){
				tmp = info[i].number - info[k].number;
				if(tmp < 0)tmp += n;
				if(tmp > (n-1)/2)tmp = n - tmp;
				checkTable[tmp]++;
			}
		}
	}

	int limit = (n-1)/2;

	for(int i = 1; i <= limit; i++)printf("%d\n",checkTable[i]);

}


int main(){

	int n;

	while(true){
		scanf("%d",&n);

		if(n == 0)break;

		func(n);
	}

    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	while(cin >> n, n) {
		if(n==1) {
			cout << 0 << endl;
			continue;
		}
		int a[10000]={};
		int c[5000]={};
		rep2(i,1,n) {
			a[(i*i)%n]++;
		}
		vector<int> v;
		rep2(i,1,n) {
			if(a[i]!=0) v.push_back(i);
		}
		rep(i,v.size()) {
			rep(j,v.size()) {
				if(i==j) continue;
				int s = v[i]-v[j];
				if(s<0) s+=n;
				if(s>(n-1)/2) c[n-s]++;
				else c[s]++;
			}
		}
		rep2(i,1,(n+1)/2) {
			cout << c[i] << endl;
		}
	}
	return 0;
}