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<vector>
#include<algorithm>

using namespace std;

int main()
{
	int sq[10000];
	for(int n=1;n<10000;n++)	sq[n]=n*n;

	int n;
	while(scanf("%d",&n),n){
		vector<int> mod;
		for(int i=1;i<n;i++)	mod.push_back(sq[i]%n);
		sort(mod.begin(),mod.end());
		mod.erase(unique(mod.begin(),mod.end()),mod.end());

		int cnt[5000]={0};
		for(int i=0;i<mod.size();i++){
			for(int j=0;j<i;j++){
				int dif=mod[i]-mod[j];
				if     (dif<0)			dif+=n;
				else if(dif>(n-1)/2)	dif=n-dif;
				cnt[dif]++;
			}
		}

		for(int i=1;i<=(n-1)/2;i++)	printf("%d\n",2*cnt[i]);
	}

	return 0;
}

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

int main(void){
	int n;

	while(cin>>n && n){
		set<int> first;
		for(int i=1;i<n;i++){
			first.insert(i*i%n);
		}

		int max = (n-1) / 2;
		int count[max+1];
		fill(count,count+max+1,0);
		for(set<int>::iterator i = first.begin(); i != first.end(); i++){
			for(set<int>::iterator j = first.begin(); j != first.end(); j++){
				if(*i == *j) continue;

				int diff = *i - *j;
				if(diff <= 0) diff += n;
				if(diff > max) diff = n - diff;
				count[diff]++;
			}
		}

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

	return 0;
}

C++: #include <set>
#include <cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;std::set<int>::iterator s,S;for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(s=t.begin();s!=t.end();s++)for(S=s;++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<iostream>
#include<algorithm>
#include<vector>

using namespace std;

const int MAX = 10000;
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(0);
  V.push_back(INF);
  sort(V.begin(),V.end());
  vector<int> VV;
  int now = 0;
  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++)
      if(i!=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++)
    cout << data[i] << endl;
}


int main(){
  while(cin >> n && n){
    solve();
    print();
  }
  return 0;
}

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

int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> v;
		std::map<int, int> m;

		for(int i=1;i<=(n-1)/2;i++){
			if(std::find(v.begin(), v.end(), i*i%n) == v.end()){//まだない
				v.push_back(i*i%n);
			}
		}

		for(int i=0;i<v.size()-1;i++){
			for(int j=i+1;j<v.size();j++){
				int value = v[i] - v[j];
				if(value < 0){
					value += n;
				}
				if(value > (n-1)/2){
					value = n - value;
				}
				m[value]++;
			}
		}

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

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		set<int>aset;
		for (int i = 1; i < N; ++i) {
			int k = (i*i) % N;
			aset.emplace(k);
		}
		vector<int>nums(N);
		for (auto it = aset.begin(); it != aset.end(); ++it) {
			for (auto jt =next( it); jt != aset.end(); ++jt) {
				int sa = *it - *jt;
				if (sa < 0)sa += N;
				if (sa > (N - 1) / 2)sa = N - sa;
				nums[sa]++;
			}
		}
		for (int i = 1; i <= (N - 1) / 2; ++i) {
			cout << nums[i]*2 << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
const int PrimeMax = 100001;
int is_prime[PrimeMax];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    is_prime[i] = 1;
  }
  is_prime[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(is_prime[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        is_prime[i *(j + 2)] = 0;
      }
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  set<int> v;
  int n;
  while(cin>>n&&n){
    v.clear();
    REP(i,1,n){
      v.insert(i*i%n);
    }
    map<int,int> s;
    for(auto n3 : v){
      for(auto n2 :v){
        if(n3 != n2){
          int k = n3 - n2;
          k += (k<0)? n:0;
          k = ((n-1)/2 < k)?n-k:k;
          s[k]++;
        }
      }
    }
    REP(i,1,(n-1)/2+1){
      cout << s[i]<<endl;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int mp[10000];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		unordered_set<int>se;
		for (int i = 1; i < n; i++)se.insert(i*i%n);
		for (auto i = se.begin(); i != se.end(); i++) {
			for (auto j = se.begin(); j != se.end(); j++) {
				if (i == j)continue;
				int d = *i - *j;
				if (d < 0)d += n;
				if (d > (n - 1) / 2) d -= n;
				mp[abs(d)]++;
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++)printf("%d\n", mp[i]);
	}
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;
	int a[10000];
	int kari;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int b[10000] = {0};
		int counter[10000] = {0};
		for (int i = 0; i < n-1; i++) {
			a[i] = (i+1) * (i+1) % n;
		}
		for (int i = 0; i < n-1; i++) {
			b[a[i]] = 1; 
		}
		for (int i = 0; i < n-1; i++) {
			for (int j = 0; j < n-1; j++) {
				if (b[i] == 1 && b[j] == 1 && i+1 != j+1) {
					kari = i - j;
					if (kari < 0) {
						kari += n;
					}
					if (kari > (n-1) / 2) {
						kari = n - kari;
					}
					counter[kari]++;
				}
			}
		}
		for (int i = 0; i < n-1; i++) {
			if (counter[i] != 0) {
				cout << counter[i] << endl;
			}
		}
	}
	return 0;
}