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 <stdio.h>

using namespace std;

int main() {
	int ans[10001],m[10001],f[10001],n,i,j,k,c;
	while(cin >> n) {
		if (n==0) break;
		c=0;
		for (i=0;i<10001;i++) ans[i]=f[i]=0;
	    for (i=1;i<=(n-1)/2;i++) { k=(i*i) % n; if (f[k]==0) { f[k]=1; m[c++]=k; }} 
	for (i=0;i<c-1;i++) for (j=i+1;j<c;j++) {
          k=m[j]-m[i];
          k=k<0 ? k+n : k;
          k=k>(n-1)/2 ? n-k : k;
          ans[k]++;
          }
     for (i=1;i<=(n-1)/2;i++) cout << ans[i]*2 << 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=1;i<n;i++)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 <bits/stdc++.h>

using namespace std;


void f(int n) {
    int half = n / 2;
    set<int> squares;
    for(int i = 1; i<=half; i++) {
        squares.insert((i*i) % n);
    }
    vector<int> nums(squares.begin(), squares.end());
    int len = nums.size();
    vector<int> cts(half+1, 0);
    for(int y=1; y<len; y++) {
        for(int x=0; x<y; x++) {
            int r = nums[y] - nums[x];
            if(r>half) r = n - r;
            cts[r] += 2;
        }
    }
    for(int i=1; i<=half; i++) cout << cts[i] << endl;
}

int main() {
    int n;
    while(scanf("%d", &n), n) f(n);
    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;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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
vector<int> v;
int n;
int cnt[10010];
int main()
{
	while(1)
	{
		memset(cnt,0,sizeof(cnt));
		v.clear();
		scanf("%d",&n);
		if(n==0)break;
		for(int i=1;i<n;i++)v.pb((i*i)%n);
		SORT(v);
		v.erase(unique(all(v)),v.end());
		//cout << v.size() << endl;
		for(int i=0;i<v.size();i++)
		{
			for(int j=0;j<v.size();j++)
			{
				if(i==j)continue;
				int k=v[i]-v[j];
				if(k<0)k+=n;
				if(k>(n-1)/2)k=n-k;
				cnt[k]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++)printf("%d\n",cnt[i]);
	}
	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);
    }
    vector<int> v2(all(v));
    vary(int,ans,(n-1)/2+1,0);
    rep(i,v2.size()){
      REP(j,i+1,v2.size()){
        int k = v2[i] - v2[j];
        k += (k<0)? n:0;
        k = ((n-1)/2 < k)?n-k:k;
        ans[k]++;
      }
    }
    REP(i,1,(n-1)/2+1){
      cout << ans[i] * 2<<endl;
    }
  }
  return 0;
}

C++: #include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
#include <vector>

using namespace std;

int n, results[5000], remsv[10000];
set<int> remss;

int main() {
  for (;;) {
    scanf("%i", &n);
    if (!n) return 0;
    memset(results, 0, sizeof results);
    remss.clear();
    memset(remsv, 0, sizeof remsv);
    for (int i = 1; i < n; i++)
      remss.insert(i * i % n);
    copy(remss.begin(), remss.end(), remsv);
    for (int i = 0; i < remss.size()-1; i++)
      for (int j = i+1; j < remss.size(); j++) {
        int d = remsv[i] - remsv[j];
        if (d < 0) d += n;
        if (d > n / 2) d = n - d;
        results[d]++;
      }
    for (int i = 1; i <= n / 2; i++)
      printf("%i\n", results[i] * 2);
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int n,a[5000],b[5000];

int main(){
	while(cin>>n&&n){
		fill(b,b+(n+1)/2,0);
		set<int> s;
		rep(i,n-1)s.insert((i+1)*(i+1)%n);
		int cur=0;
		set<int>::iterator ite=s.begin();
		while(ite!=s.end()){
			a[cur++]=*ite;
			ite++;
		}
		//rep(i,cur)cout<<a[i]<<endl;cout<<cur<<endl;
		rep(i,cur)rep(j,cur){
			if(i==j)continue;
			int r=a[j]-a[i];
			if(r<0)r+=n;
			if(r>(n-1)/2)r=n-r;
			b[r]++;
		}
		rep(i,(n-1)/2)cout<<b[i+1]<<endl;
	}
}