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<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<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

int main() {
  int n;
  while(cin >> n && n) {
    set<int> s;
    repl(x, 1, n-1) {
      s.insert(x*x % n);
    }
    vector<int> c((n-1)/2+1);
    repe(a, s) {
      repe(b, s) {
        if(a == b) continue;
        if(a < b) {
          c[mind(b - a, n + a - b)]++;
        } else {
          c[mind(a - b, n + b - a)]++;
        }
      }
    }
    repl(x, 1, (n-1)/2) {
      cout << c[x] << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        set<int> si;
        for(int i=1; i<n; ++i)
            si.insert(i*i%n);

        vector<int> ret((n-1)/2+1, 0);
        set<int>::iterator it1, it2;
        for(it1=si.begin(); it1!=si.end(); ++it1){
            for(it2=si.begin(); it2!=si.end(); ++it2){
                if(it1 == it2)
                    continue;
                int a = (*it1) - (*it2);
                if(a < 0)
                    a += n;
                if(a > (n-1)/2)
                    a = n - a;
                ++ ret[a];
            }
        }

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

C++: #include <set>
#include <cstdio>
#include <cstring>
using namespace std;
int sq[10000],v[9999];
int main(){
	int i,n;
	for(i=1;i<10000;i++)sq[i]=i*i;
	for(;scanf("%d",&n),n;){
		set<int>s;
		memset(v,0,sizeof(v));
		for(i=1;i<n;i++)s.insert(sq[i]%n);
		set<int>::iterator is,iS;
		for(is=s.begin();is!=s.end();is++)
			for(iS=is,iS++;iS!=s.end();iS++){
				i=*iS-*is;
				if(i>(n-1)/2)i=n-i;
				v[i]++;
			}
		for(i=1;i<=(n-1)/2;i++)printf("%d\n",v[i]*2);
	}
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;

# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12

template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };


int main()
{
	int n;
	while (cin >> n&&n)
	{
		set<int> a;
		for (int i = 1; i<n; i++)
		{
			long long x = (long long)i*i;
			x %= n;
			a.insert(x);
		}
		int ans[11000] = {};
		for (auto it : a)
		{
			for (auto i : a)
			{
				if (i == it)continue;
				int d = i - it;
				while (d<0)d += n;
				while (d>(n - 1) / 2)d = n - d;
				while (d<0)d += n;
				while (d>(n - 1) / 2)d = n - d;
				ans[d]++;
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++)
		{
			cout << ans[i] << endl;
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		priority_queue<int> pq;
		for (int i = 1; i < n; i++) {
			pq.push((i*i)%n);
		}
		int counter = 0;
		vector<int> hyou;
		while (!pq.empty()) {
			hyou.push_back(pq.top());
			pq.pop();
			counter++;
			while (!pq.empty()) {
				if (pq.top() == hyou[counter-1]) {
					pq.pop();
				} else {
					break;
				}
			}
		}
		vector<int> data(n+1, 0);
		int a;
		for (int i = 0; i < counter; i++) {
			for (int j = 0; j < counter; j++) {
				if (i == j) {
				} else {
					a = hyou[i]-hyou[j];
					if (a < 0) {
						a += n;
					}
					if (a > (n-1)/2) {
						a = n - a;
					}
					data[a]++;
				}
			}
		}
		for (int i = 1; i <= (n-1)/2; i++) {
			cout << data[i] << endl;
		}
	}
	return 0;
}

C++: #include <set>
#include <cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;for(i=0;i<n;)v[++i]=0,t.insert(i*i%n);for(auto s=t.begin(),S=s,T=t.end();s!=T;S=++s)for(;++S!=T;v[i>n/2?n-i:i]+=2)i=*S-*s;for(i=0;i<n/2;)printf("%d\n",v[++i]);}}