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>
#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 = p[i] - p[j];
					if (z < 0) { z += n; }
					if (z > (n - 1) / 2) { z = n - z; }
					x[z]++;
				}
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++) {
			cout << x[i] << endl;
		}
	}
}

C++: #include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,n,ama[10000],amb[10000],p,x,ke[10000];
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	ama[i]=0;
		for(i=1;i<n;i++)	{
			x=(i*i)%n;
			ama[x]=1;
		}
		p=0;
		for(i=0;i<n;i++)	{
			if(ama[i]==1)	{
				amb[p]=i;
				p++;
			}
		}
		for(i=1;i<=(n-1)/2;i++)	ke[i]=0;
		for(i=0;i<p;i++)	{
			for(j=0;j<p;j++)	{
				if(i!=j)	{
					x=amb[i]-amb[j];
					if(x<0)	x+=n;
					if(x>(n-1)/2)	x=n-x;
					ke[x]++;
				}
			}
		}
		for(i=1;i<=(n-1)/2;i++)	{
			printf("%d\n",ke[i]);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<29)


int main(){
	int n;
	while(cin>>n&&n){
		vector<int> v(n-1),hist((n-1)/2,0);
		for(int i=1;i<n;i++)v[i-1]=i*i%n;
		sort(v.begin(),v.end());
		v.erase(unique(v.begin(),v.end()),v.end());
		for(int i=0;i<v.size();i++){
			for(int j=0;j<v.size();j++){
				if(i==j)continue;
				int s=v[i]-v[j];
				while(s<0||(n-1)/2<s){//cout<<s<<endl;
					if(s<0)s+=n;
					else s=n-s;
				}
				hist[s-1]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			cout<<hist[i-1]<<endl;
		}
	}
	return 0;
}

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

using namespace std;

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;
			}
		}
		sort(b, b+p);
		for(int i = 0; i < p-1; i++){
			for(int j = i+1; j < p; j++){
				t = b[j] - b[i];
				if(t > m){
					t = n - t;
				}
				a[t] += 2;
			}
		}
		for(int i = 1; i <= m; i++){
			cout << a[i] << endl;
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int cnt[5010];
int main(){
  int n;
  while(cin>>n&&n){
    set<int> st;
    vector<int> v;
    for(int i=1;i<n;i++){
      st.insert(i*i%n);
    }
    set<int>::iterator it=st.begin();
    while(it!=st.end()){
      v.push_back(*it);
      ++it;
    }
    for(int i=0;i<(n-1)/2;i++)cnt[i]=0;
    for(int i=0;i<v.size();i++){
      for(int j=i+1;j<v.size();j++){
	int x=v[j]-v[i];
	x=min(x,n-x);
	cnt[x]+=2;
      }
    }
    for(int i=1;i<=(n-1)/2;i++)cout<<cnt[i]<<endl;
  }
  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 = p[i] - p[j];
					if (z < 0) { z += 11; }
					if (z > (n - 1) / 2) { z = 11 - z; }
					x[z]++;
				}
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++) {
			cout << x[i] << endl;
		}
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


const int INF = 1 << 20;
struct P
{
	int r1, k1;
	vint ok;
};


int main()
{
    int n, p;
	cin >> n;
	cin.ignore();
	
	vector<P> v(n);
	rep(i, n)
	{
		cin >> v[i].r1;
		
		int k1;
		cin >> k1;
		
		rep(j, k1)
		{
			int buf;
			cin >> buf;
			v[i].ok.push_back(buf);
		}
	}
	
	cin >> p;
	
	vector<vint> G(n, vint(n, INF));
	
	rep(i, n)
	{
		rep(j, v[i].ok.size())
		{
			G[v[i].r1 - 1][v[i].ok[j] - 1] = 1;
		}
	}
	
	rep(k, n) rep(i, n) rep(j, n)
		chmin(G[i][j], G[i][k] + G[k][j]);
		
	rep(i, p)
	{
		int s1, d1, v1;
		cin >> s1 >> d1 >> v1;
		
		int cost = G[s1 - 1][d1 - 1];
		if(cost == INF || v1 <= cost)
		{
			cout << "NA" << endl;
		}
		else
		{
			cout << cost + 1 << endl;
		}
	}
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

#define SQR(x) ((x) * (x))
int main()
{
    for(int n; cin >> n && n != 0;)
	{
		int hn = (n - 1) / 2;
		vint num(hn, 0), v(n - 1);
		
		
		rep(i, n - 1) v[i] = SQR(i + 1) % n; 
		
		sort(ALL(v));
		v.erase(unique(ALL(v)), v.end());
		
		
		rep(i, v.size()) rep(j, v.size()) if(i != j)
		{
			int ab = v[i] - v[j];
			
			if(ab < 0) ab += n;
			if(hn < ab) ab = n - ab;
			
			num[ab - 1]++;
		}
		
		rep(i, hn)
			cout << num[i] << endl;
	}
}