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<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;
        reps(i,1,n/2+1){
            int tmp = (i*i)%n;
            if(flg[tmp]++)continue;
            numbers.PB(tmp);
        }
        int cnt[12800]={0};
        int len = numbers.size();
        sort(numbers.begin(),numbers.end());
        rep(i,len){
            reps(j,i+1,len){
                int tmp = numbers[j]-numbers[i];
                if(tmp > (n-1)/2)tmp = n-tmp;
                cnt[tmp]++;
            }
        }
        reps(i,1,(n-1)/2+1){
            printf("%d\n",2*cnt[i]);
        }
    }
    return 0;
}

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

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[m];
        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 < m; i++)
            cout << hist[i] << endl;
    }
    return 0;    
}

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

using namespace std;

int func(int s, int t, int m, int n)
{
	int v = s - t;
	
	if(v < 0){
		v += n;
	}
	if(v > m){
		v = n - v;
	}
	
	return v;
}

int main()
{
	int n, m, a[5001], p, b[10001], t;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		m = (n-1)/2;
		fill(a, a+m, 0);
		p = 0;
		for(int i = 1; i < n; i++){
			t = (i*i)%n;
			bool f = true;
			for(int j = 0; j < p; j++){
				if(t == b[j]){
					f = false;
					break;
				}
			}
			if(f){
				b[p++] = t;
			}
		}
		
		for(int i = 0; i < p-1; i++){
			for(int j = i+1; j < p; j++){
				a[func(b[i], b[j], m, n)]++;
				a[func(b[j], b[i], m, n)]++;
			}
		}
		for(int i = 1; i <= m; i++){
			cout << a[i] << endl;
		}
	}
	
	return 0;
}

C++: g#include <iostream>
#include <set>
#include <cstring>
using namespace std;

int n;
int main() {
    while (cin >> n, n != 0) {
        set<int> mod;
        for (int i = 1; i < n; i++) 
            mod.insert( (i*i) % n );

        int count[(n-1)/2+1];
        memset(count, 0, sizeof(count));
        for (set<int>::iterator si = mod.begin();
                si != mod.end(); si++) {
            for (set<int>::iterator sj = mod.begin();
                    sj != mod.end(); sj++) {
                if (*si == *sj) continue;
                int dif = *si - *sj;
                if (dif < 0) dif += n;
                if (dif > (n-1)/2) dif = n - dif;
                count[dif]++;
            }
        }

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

C++: #include <cstdio>           // printf(), scanf()
#include <set>

using namespace std;

const int MAX_N = 10000;
const int MAX_R = 5000;

void
solve(int n)
{
	int bins[MAX_N / 2];
	set<int> remains;
	int re[MAX_R];

	int ix = 0;
	for (int i = 1; i < n; ++i)
	{
		int r = (i * i) % n;

		if (remains.find(r) == remains.end())
		{
			remains.insert(r);
			re[ix++] = r;
		}
	}

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

	for (int i = 0; i < ix; ++i)
	{
		for (int j = 0; j < ix; ++j)
		{
			if (i != j)
			{
				int d = re[i] - re[j];
				if (d < 0)
					d += n;

				if (d > m)
					d = n - d;

				bins[d]++;
			}
		}
	}

	for (int i = 1; i <= m; ++i)
		printf("%d\n", bins[i]);
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		solve(n);
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; i++)
#define REP(n) rep(i, n)
//#define int long long
using namespace std;

int n, idx, x, arr[10000], c[10000];
set<int> si; 

signed main()
{
    while (cin >> n, n)
    {   
        idx = 0;
        si.clear();

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

        for (int i=1; i<n; i++)
        {   
            x = (i * i) % n;
            if (si.find(x) == si.end())
            {   
                si.insert(x);
                arr[idx++] = x;
            }   
        }   

        rep(i, idx)
        {   
            rep(j, idx)
            {   
                if (i == j) continue;
                int sub = arr[i] - arr[j];
                if (sub < 0) sub += n;
                if (sub > (n - 1) / 2) sub = n - sub;
                c[sub]++;
            }   
        }   

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

    return 0;
}

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;
		reps(i,1,n){
			int tmp = i*i;
			while(tmp>=n)tmp-=n;
			if(flg[tmp]++)continue;
			numbers.PB(tmp);
		}
		int len = numbers.size();
		int harf = (n-1)/2;
		rep(i,len){
			rep(j,len){
				if(i == j)continue;
				int tmp = numbers[i]-numbers[j];
				if(tmp < 0)tmp += n;
				if(tmp > harf)tmp = n-tmp;
				cnt[tmp]++;
			}
		}
		map <int,int> :: iterator it;
		for(it = cnt.begin(); it != cnt.end(); it++){
			printf("%d\n",it->se);
		}
	}
	return 0;
}