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<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 %d\n", res[i]);

//*/

//*/ break;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(i*i%n);
        sort(num.begin(),num.end());
        vector<int> number;
        number.push_back(num[0]);
        for(int i=1;i<num.size();i++)if(num[i]-num[i-1]!=0)number.push_back(num[i]);
        int ans[100000]={};
        for(int i=0;i<number.size();i++){
            for(int j=0,k;j<number.size();j++){
                k=number[i]-number[j];
                if(k<0)k+=n;
                if(k>n/2)k=n-k;
                ans[k]++;
            }
        }
        for(int i=1;i<=n/2;i++)cout<<ans[i]<<endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int times[10000/2];
		memset(times, 0, sizeof(times));
		vector<int> v;
		for (int i = 1; i < n; ++i)
			v.push_back(i*i%n);
		sort(v.begin(), v.end());
		int m = unique(v.begin(), v.end()) - v.begin();
		for (int i = 0; i < m; ++i)
		{
			for (int j = i+1; j < m; ++j)
			{
				int t = v[j] - v[i];
				if (t > n/2)
					t = n - t;

				++times[t];
			}
		}

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

	return 0;
}

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

bool flg[10002];
int cnt[10002];

int main(){
  int n;

  while(cin >> n, n){
    memset(flg, 0, sizeof(flg));
    memset(cnt, 0, sizeof(cnt));

    for(int i = 1; i < n; i++){
      flg[(i * i) % n] = true;
    }

    for(int i = 0; i < n; i++){
      if(!flg[i]) continue;

      for(int j = i + 1; j < n; j++){
	if(!flg[j]) continue;

	int cal = j - i;
	if(cal > (n - 1) / 2) cal = n - cal;
	cnt[cal]++;

	cal = i - j + n;
	if(cal > (n - 1) / 2) cal = n - cal;
	cnt[cal]++;
      }
    }

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

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
const bool DEBUG = false;

#define MAX 10010
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end())
signed main() {
	for (int n; cin >> n&&n;) {
		vector<int> cnt((n - 1) / 2 + 1, 0);
		vector<int> v;
		rep(i, 1, n) {
			v.emplace_back((i*i) % n);
		}
		sort(all(v));
		UNIQUE(v);
		dumpc(v);
		rep(i, 0, v.size())rep(j, 0, v.size()) {
			if (v[i] == v[j])continue;
			int diff = v[i] - v[j];
			if (diff < 0)diff += n;
			if (diff > (n - 1) / 2.0)diff = n - diff;
			dump(diff);
			dump(cnt.size());
			cnt[diff]++;
		}
		dumpc(cnt);
		rep(i, 1, (n - 1) / 2 + 1)cout << cnt[i] << endl;
	}
	return 0;
}

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

C++: #include <set>
#include <cstdio>
#include <cstring>
using namespace std;
int v[9999];
int main(){
	int i,n;
	for(;scanf("%d",&n),n;){
		set<int>s;
		memset(v,0,sizeof(v));
		for(i=1;i<n;i++)s.insert(i*i%n);
		set<int>::iterator is,iS;
		for(is=s.begin();is!=s.end();is++)
			for(iS=is,iS++;iS!=s.end();iS++){
				i=*iS-*is;
				if(i>(n-1)/2)i=n-i;
				v[i]++;
			}
		for(i=1;i<=(n-1)/2;i++)printf("%d\n",v[i]*2);
	}
}