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 <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	while(cin >> n, n) {
		int a[10000]={};
		int c[5000]={};
		rep2(i,1,n) {
			a[(i*i)%n]++;
		}
		vector<int> v;
		rep(i,n) {
			if(a[i]!=0) v.push_back(i);
		}
		rep(i,v.size()) {
			rep(j,v.size()) {
				if(i==j) continue;
				int s = v[i]-v[j];
				if(s<0) s+=n;
				if(s>(n-1)/2) c[n-s]++;
				else c[s]++;
			}
		}
		rep2(i,1,(n+1)/2) {
			cout << c[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-1;)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]);}}

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

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

set<int> app;

main(){
	int n;
	while(scanf("%d",&n)){
		if(n==0)break;
		
		app.clear();
		
		for(int i=1;i<n;i++){
			app.insert(i*i%n);
		}
		vector<int> vapp((n-1)/2);
		for(set<int>::iterator sp=app.begin();sp!=app.end();sp++){
			for(set<int>::iterator tsp=app.begin();tsp!=app.end();tsp++){
				if(sp==tsp)continue;
				int diff=*tsp-*sp;
				if(diff<0)diff+=n;
				if(diff>(n-1)/2)diff=n-diff;
				vapp[diff-1]++;
			}
		}
		for(int i=0;i<vapp.size();i++){
			cout<<vapp[i]<<endl;
		}
	}
}

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

const int MAX = 5001;
const int INF = (1<<20);

int data[MAX],n;


void solve(){
  vector<int> V;
  fill(data,data+MAX,0);
  for(int i = 1; i < n; i++){
    V.push_back((i*i)%n);
  }
  V.push_back(-1);
  V.push_back(INF);
  sort(V.begin(),V.end());
  vector<int> VV;
  int now = -1;
  while(1){
    now = *upper_bound(V.begin(),V.end(),now);
    if(now == INF) break;
    VV.push_back(now);
  }
  for(int i = 0; i < VV.size(); i++)
    for(int j = 0; j < VV.size(); j++){
      int num = VV[i]-VV[j];
      if(num < 0) num += n;
      if(num > (n-1)/2) num = n-num;
      data[num]++;
    }
}

void print(){
  for(int i = 1; i <= (n-1)/2; i++)
    printf("%d\n",data[i]);
}


int main(){
  while(scanf("%d",&n) && n){
    solve();
    print();
  }
  return 0;
}

C++: #include<stdio.h>
#include<list>
#include<algorithm>
using namespace std;
int main()
{
	int a[8096];
	list<int> con;
	list<int>::iterator itei,itej;
	int n,i,value;
	while(scanf("%d",&n),n)
	{
		con.clear();
		fill(a,a+sizeof(a)/sizeof(a[0]),0);

		for(i=1; i<=(n-1)/2; ++i)
			con.push_back(i*i%n);
		con.sort();
		con.unique();

		for(itei=con.begin(); itei!=con.end(); ++itei)
			for(itej=con.begin(); itej!=con.end(); ++itej)
			{
				if(itei!=itej)
				{
					value = *itei - *itej;
					if(value<0) value+=n;
					if(value> (n-1)/2) value = n-value;
					++a[value];
				}
			}
		for(i=1; i<=(n-1)/2; ++i)
			printf("%d\n",a[i]);
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int N = 10010;
int a[N];
int cnt[N];

int main(){
	int n;
	while(cin >> n, n){
		int m = (n-1)/2;
		MEMSET(a, 0);
		MEMSET(cnt, 0);
		FOR(i, 1, n) a[i*i%n] = 1;
		vector<int> v;
		v.reserve(n);
		rep(i, n) if(a[i]) v.push_back(i);
		rep(i, v.size()) rep(j, v.size()){
			if(i == j) continue;
			int x = v[i]-v[j];
			if(x < 0) x += n;
			if(x > m) x = n-x;
			++cnt[x];
		}
		
		FOR(i, 1, m+1) cout << cnt[i] << endl;
	}


	return 0;
}

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

int main(){
  int n;
  int sq[10000],fr[5000];
  vector<int> com;
  int tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=1;i<n;i++)sq[i] = (i*i)%n;
    com.clear();

    for(int i=1;i<n;i++){
      bool f = true;
      for(int j=0;j<com.size();j++){
	if(com[j]==sq[i]){
	  f = false;
	  break;
	}
      }
      if(f)com.push_back(sq[i]);
    }
 
    for(int i=0;i<=(n-1)/2;i++)fr[i] = 0;

    for(int i=0;i<com.size();i++){
      for(int j=0;j<com.size();j++){
	if(i!=j){
	  tmp = com[i]-com[j];
	  if(tmp<0)tmp+=n;
	  if(tmp>(n-1)/2)tmp = n - tmp;
	  fr[tmp]++;
	}
      }
    }

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

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

#define MAX_N 100000

long long q[MAX_N];
long long x[MAX_N];
long long n;
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++) {
				long long z;
				z = abs(n * 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 <set>
#include <algorithm>

using namespace std;


int main(void)
{
	int n;
	set<int> target;
	int data[10000];
	int change[10000];

	while( cin >> n && n != 0 ){
		target.clear();
		for( int i = 0;i < 10000;i++ ) change[i] = data[i] = 0;
		for( int i = 1;i < n;i++ ){
			target.insert( i * i % n );
		}

		copy( target.begin(), target.end(), change );
		

		int piyo = target.size();
		int hoge = ( n - 1 ) / 2;
		for( int i = 0;i < piyo;i++ ){
			for( int j = 0;j < piyo;j++ ){
				int answer = change[i] - change[j];
				if( answer == 0 ) continue;
				while( 1 ){
					if( answer < 0 ){ answer += n; continue; }
					else if( answer > hoge ){ answer = n - answer; continue; }
					data[answer]++;
					break;
				}
			}
		}

		for(  int i = 1;i <= hoge;i++ ){
			cout << data[i] << endl;
		}
	}

	return 0;
}