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<cstdio>
#include<algorithm>
#include<climits>
#include<vector>
#include<cstdlib>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<sstream>
using namespace std;

int N;

int calc(int a, int b){
	int res = a - b;
	if( res < 0 ) res += N;
	if( res > (N-1)/2 ) return res = N - res;
	return res;
}

int main(){
	while(cin >> N, N){
		int cnt[10000] = {};
		vector<int> s;
		for(int i = 1; i < N; i++){
			s.push_back( (i*i)%N );
		}
		sort( s.begin(), s.end() );
		s.erase( unique( s.begin(), s.end() ), s.end() );
		for(int i = 0; i < s.size(); i++){
			for(int j = 0; j < s.size(); j++){
				if( s[i] == s[j] ) continue;
				cnt[ calc(s[i], s[j]) ]++;
			}
		}
		for(int i = 1; i <= (N-1)/2; i++) printf("%d\n", cnt[i]);
	}
	return 0;
}

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

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;

int main(){
  while(cin >> n, n){
    bitset<11234> a;
    rep(i, 1, n) a[i * i % n] = 1;
    for(int i = 1; i <= n / 2; ++i){
      int cnt = 0;
      REP(j, n) if(a[j] && a[(j + i) % n]) ++cnt;
      cout << cnt * 2 << endl;
    }
  }
}

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 n;
	while(scanf("%d", &n), n){
		vi nums(n, 0);
		reep(i, 1, n)
			nums[(i*i)%n] |= 1;
		reep(i, 1, (n+1)/2){
			int sum = 0;
			rep(j, n)
				sum += nums[j] & nums[(j+i)%n];
			printf("%d\n", sum * 2);
		}
	}
	
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int data[20000];

int f(int tmp,int n){
    int pre = tmp;
    while(1){
        bool f=true;
        if(tmp<0)tmp+=n,f=false;
        if(tmp>(n-1)/2)tmp = n-tmp,f=false;
        if(f)break;
    }
    data[10000+pre] = tmp;
    return tmp;
}

int main(){
    int n;
    while(cin>>n&&n){
        rep(i,20000)data[i] = -1;
        set<int> a;
        for(int i=1;i<n;i++){
            a.insert( (i*i)%n );
        }
        
        vector<int> vec;
        for(int x : a) vec.pb(x);
        int b[10000]={};

        rep(i,vec.size()){
            rep(j,vec.size()){
                if(i==j)continue;
                int tmp = vec[i]-vec[j];
                if(data[10000+tmp]!=-1)tmp = data[10000+tmp];
                else tmp = f(tmp,n);
                b[tmp]++;
            }
        }
        int num = (n-1)/2;
        for(int i=1;i<=num;i++){
            printf("%d\n",b[i]);
        }
    }
}

C++: // 2011/03/14 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		bool rem[10000];
		for(int i=0; i<n; i++)
			rem[i] = false;

		for(int i=1; i<=n-1; i++)
			rem[i*i%n] = true;

		int cnt[5000];
		for(int i=1; i<=(n-1)/2; i++)
			cnt[i] = 0;

		for(int a=0; a<n; a++){
			if(!rem[a])
				continue;

			for(int b=a+1; b<n; b++){
				if(!rem[b])
					continue;

				int c = b-a;
				if(c>(n-1)/2)
					c = n-c;
				cnt[c]++;
			}
		}

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

	return 0;
}

C++: 
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,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 <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n, a[20000];
	
	bool exist[20000];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		for(int i = 1; i < n; i++){
			exist[i] = false;
			a[i] = 0;
		}
		for(int i = 1; i < n; i++){
			exist[(i * i) % n] = true;
		}
		
		int dummy;
		
		for(int i = 1; i < n; i++){
			for(int j = 1; j < n; j++){
				if(i == j){
					continue;
				}
				if(exist[i] && exist[j]){
					dummy = i - j;
					if(dummy < 0){
						dummy += n;
					}
					if(dummy > (n - 1) / 2){
						dummy = n - dummy;
					}
					a[dummy]++;
				}
			}
		}
		
		for(int i = 1; i <= n / 2; i++){
			printf("%d\n", a[i]);
		}
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<set>
#include<string.h>
void calc(int n){
int t,data[5001],p=0,up,ans[5001];
std::set<int> c1;
memset(ans,0,5001*4);

for(int i=1;i<n;i++){
	t=(i*i)%n;
	if(c1.find(t)==c1.end()){
		c1.insert(t);
		data[p]=t;
		p++;
	}
}
up=(n-1)/2;
for(int i=0;i<p;i++){
	for(int j=0;j<p;j++){
		if(i==j) continue;
		t=data[i]-data[j];
		t+=t<0?n:0;
		t=t>up?n-t:t;
		ans[t]++;
	}
}
for(int i=1;i<=up;i++){
	printf("%d\n",ans[i]);
}
}
int main(){
int n;
scanf("%d",&n);
while(n!=0){
	calc(n);
	scanf("%d",&n);
}
}