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 _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(const _Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,const _Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif


void solve(int n){
    int m = (n-1)/2;
    set<int> s;
    FROMTO(i,1,n){
        int k = (i*i) % n;
        s.insert(k);
    }
    vector<int> v;
    v.insert(v.end(), ALL(s));
    prfe(v);
    int nv = v.size();
    vector<int> r(m);
    REP(i,nv){
        REP(j,nv){
            if(i == j) continue;
            int k = abs(v[i] - v[j]);
            if(k > m) k = n - k;
            r[k-1]++;
        }
    }
    FOREACH(it,r) cout << *it << endl;
}

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

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

using namespace std;

int main()
{
	int exist[16384];
	int nums[16384], ans[8192];
	int i, j, n, size, half, p;
	
	while(scanf("%d", &n), n){
		for(i=0; i<n; ++i)
			exist[i] = 0;
		for(i=1; i<n; ++i)
			exist[(i*i)%n] = 1;
		
		size = 0;
		for(i=0; i<n; ++i){
			if(exist[i])
				nums[size++] = i;
		}

		half = (n-1) / 2;
		for(i=1; i<=half; ++i)
			ans[i] = 0;

		for(i=0; i<size; ++i){
			for(j=0; j<i; ++j){
				++ans[(p=abs(nums[i]-nums[j]))>half?n-p:p];
			}
		}
		for(i=1; i<=half; ++i)
			printf("%d\n", ans[i]*2);
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int,int> P;

int n;

int main(){
  while(cin >> n ,n){
    int ans[(n-1)/2];
    memset(ans,0,sizeof(ans));
    vector<int> v;
    vector<int> nv;
    int nn = n;

    for(int i = 1 ; i < nn ; i++){      
      v.push_back(i*i%n);
    }
    sort(v.begin(),v.end());
    for(int i = 1 ; i < nn ; i++){ 
      if(v[i] != v[i-1]){ 
	nv.push_back(v[i-1]);
      }       
    }
   
    for(int i = 0 ; i < nv.size(); i++){
      for(int j = 0 ; j < nv.size() ; j++){
	if(i == j) continue;

	int res = nv[i]-nv[j];
	if(res < 0){
	  res += nn;
	}
	if(res > (nn-1)/2){
	  res = nn - res;
	}
	ans[res-1]++;
      }
    }

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

  return 0;
}

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

int main(){
	int n,delta;
	while(cin >> n,n){
		vector<int> table(n,-1);
		int t[5001] = {0};
		for(int i=1;i<n;i++){
			table[i] = (i*i)%n;
		}
		sort(table.begin(),table.end());
		table.erase(unique(table.begin(),table.end()),table.end());
		
		for(int i=1;i<table.size();i++){
			for(int j=1;j<table.size();j++){
				delta = table[i] - table[j];
				if(delta<0)delta+=n;
				if(delta>(n-1)/2)delta=n-delta;
				t[delta]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			cout << t[i] << endl;
		}
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-9
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;
int main(){
	int n;
	while(scanf("%d",&n),n){
		bool flg[12800]={0};
		vector < int > numbers;
		map <int,int> cnt;
		int half = (n-1)/2;
		reps(i,1,half+1){
			int tmp = i*i;
			if(flg[tmp%n]++)continue;
			numbers.PB(tmp%n);
		}
		int len = numbers.size();
		rep(i,len){
			rep(j,len){
				if(i == j)continue;
				int tmp = numbers[i]-numbers[j];
				if(tmp < 0)tmp += n;
				if(tmp > half)tmp = n-tmp;
				cnt[tmp]++;
			}
		}
		map <int,int> :: iterator it;
		for(it = cnt.begin(); it != cnt.end(); it++){
			cout << it->se << endl;
		}
	}
	return 0;
}