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 <stdio.h>
#include <set>
#include <vector>
using namespace std;
const int N=1e4+10;
#define PB push_back
int main(){
    int n,a[N],mid;
    set<int> s;
    vector<int> v;
    while(scanf("%d",&n)!=EOF){
        if(n==0)return 0;
        s.clear();
        v.clear();
        for(int i=1;i<n;i++)s.insert((i*i)%n);
        mid=n>>1;
        for(int i=1;i<=mid;i++)a[i]=0;
        for(int i:s)v.PB(i);
        for(int i=0;i<v.size();i++)for(int j=0;j<v.size();j++)if(i!=j){
            if(v[j]-v[i]>mid)a[n-(v[j]-v[i])]++;
            else a[v[j]-v[i]]++;
        }
        for(int i=1;i<=mid;i++)printf("%d\n",a[i]*2);
    }
}

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

int n;

typedef long long ll;

void solve()
{
	map<ll,int> M;
	vector<int> V;
	vector<int> res((n-1)/2,0);
	for(ll i=1;i<n;i++){
		int t=i*i%n;
		if(!M.count(t)){
			V.push_back(t);
			M[t]=0;
		}
	}

	for(int i=0;i<V.size();i++){
		for(int j=i+1;j<V.size();j++){
			int t=V[i]-V[j];
			if(t<0) t+=n;
			if(t>(n-1)/2) t=n-t;
			res[t-1]++;
		}
	}
	for(int i=0;i<res.size();i++)
		cout<<res[i]*2<<endl;

}

int main()
{
	while(cin>>n){
		if(n==0) break;
		solve();
	}
	return 0;
}

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

long long a[10000];

int main(){
	int n;
	while(cin >> n && n){
		int ans[10000] = {};
		vector<int> g;
		for(int i = 1 ; i < n ; i++){
			int calc = i * i % n;
			g.push_back(calc);
		}
		sort(g.begin(),g.end());
		g.erase(unique(g.begin(),g.end()),g.end());
		for(int i = 0 ; i < g.size() ; i++)
			for(int j = 0 ; j < g.size() ; j++){
				if( i != j ){
					int x = g[i] - g[j];
					if( x < 0 ) x += n;
					if( x > n/2 ) x = n - x;
					ans[x]++;
				}
			}
		for(int i = 1 ; i <= n / 2 ; i++)
			cout << ans[i] << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<int> a;
    for (int i = 1; i < n; i++) {
      a.emplace_back(i * i % n);
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    vector<int> ans((n - 1) / 2 + 1);
    for (int i = 0; i < int(a.size()); i++) {
      for (int j = 0; j < int(a.size()); j++) {
        int tmp = a[j] - a[i];
        if (tmp == 0) continue;
        if (tmp < 0) tmp += n;
        if (tmp > (n - 1) / 2) tmp = n - tmp;
        ans[tmp]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << ans[i] << endl;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

bool use[10000];
int res[10000];
int cal[10000];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    if(!n)break;

    int ma = (n - 1) / 2, hd = 0;
    rep(i, n)use[i] = false;
    rep1(i, n){
      int x = (i * i) % n;
      use[x] = true;
    }
    rep1(i, n)if(use[i])cal[hd++] = i;

    rep(i, ma)res[i] = 0;
    rep(i, hd)rep(j, hd)if(i != j){
      int tmp = cal[j] - cal[i];
      if(tmp < 0)tmp += n;
      if(tmp > ma)tmp = n - tmp;
      ++res[tmp - 1];
    }
    rep(i, ma)printf("%d\n", res[i]);

//*/

//*/ break;
  }
  return 0;
}

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

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<int> sqmod;
    sqmod.reserve(N);
    for(int i = 1; i < N; ++i)
      sqmod.emplace_back((i*i)%N);
    sort(begin(sqmod), end(sqmod));
    sqmod.erase(unique(begin(sqmod), end(sqmod)), end(sqmod));
    vector<int> cnt((N - 1) / 2 + 1, 0);
    for(int i : sqmod) {
      for(int j : sqmod) {
        if(i == j) continue;
        int diff = i - j;
        if(diff < 0) diff += N;
        if(diff > (N - 1)/2) diff = N - diff;
        cnt[diff]++;
      }
    }
    for(int i = 1; i < (int)cnt.size(); ++i) {
      cout << cnt[i] << endl;
    }
  }
}

C++: #include <stdio.h>
#include <set>
#include <vector>
using namespace std;
const int N=1e4+10;
#define PB push_back
int main(){
    int n,a[N],mid;
    set<int> s;
    vector<int> v;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        s.clear();
        v.clear();
        for(int i=1;i<n;i++)s.insert((i*i)%n);
        mid=n>>1;
        for(int i=1;i<=mid;i++)a[i]=0;
        for(int i:s)v.PB(i);
        for(int i=0;i<v.size();i++)for(int j=0;j<v.size();j++)if(i!=j){
            if(v[j]-v[i]>mid)a[n-(v[j]-v[i])]++;
            else a[v[j]-v[i]]++;
        }
        for(int i=1;i<=mid;i++)printf("%d\n",a[i]*2);
    }
}

C++: #include<iostream>
#include<set>
#include<cstring>

using namespace std;

set<int> SubData;
set<int>::iterator it,tmp;
int CntData[10000];

void solve(int n, int limit) {
	int result;

    //cout<<"result_before: "<<*it<<"-"<<*tmp<<"="<<result<<endl;
	result = *it - *tmp;
	while (result<0 || result>limit) {
		if (result < 0) {
			result += n;
		}
		else if (result > limit) {
			result = n - result;
		}
	}
	//cout<<"result_after:"<<result<<endl;
	CntData[result]++;
}

int main() {
	int n, limit;

	while (cin >> n, n) {
		SubData.clear();
		memset(CntData, 0, sizeof(CntData));
		limit = (n - 1) / 2;
		for (int i = 1; i < n; i++) {
			SubData.insert((i*i) % n);
		}
		for (it = SubData.begin(); it != SubData.end(); it++) {
			for (tmp = SubData.begin(); tmp != SubData.end(); tmp++) {
				if (*tmp == *it) {
					continue;
				}
				solve(n, limit);
			}
		}
		limit++;
		for (int i = 1; i < limit; i++) {
			if (CntData[i] != 0) {
				cout << CntData[i] << endl;
			}
		}

	}

	return 0;
}