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<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[10010];
int b[10010];

int main() {
	int n;
	while(n=in()){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int i,j;
		for(i=1;i<n;i++){
			a[i*i%n]=1;
		}
		for(i=1;i<n;i++){
			if(a[i]==0)continue;
			for(j=i+1;j<n;j++){
				if(a[j]==0)continue;
				int k=i-j;
				if(k<0)k+=n;
				if(k>(n-1)/2)k=n-k;
				b[k]+=2;
			}
		}
		for(i=1;i<(n+1)/2;i++)cout<<b[i]<<endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    int n;
    while(cin>>n&&n){
        set<int> a;
        for(int i=1;i<n;i++){
            int tmp = 0;
            tmp = i*i;
            tmp %= n;
            a.insert(tmp);
        }
        
        vector<int> vec;
        for(int x : a) vec.pb(x);
        map<int,int> b;

        rep(i,vec.size()){
            rep(j,vec.size()){
                if(i==j)continue;
                int tmp = vec[i]-vec[j];
                while(1){
                    bool f=true;
                    if(tmp<0)tmp+=n,f=false;
                    if(tmp>(n-1)/2)tmp = n-tmp,f=false;
                    if(f)break;
                }
                b[tmp]++;
            }
        }
        for(pii x : b){
            printf("%d\n",x.second);
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

int main()
{
	vector <int> n2;
	for (int i = 1; i <= 10000; i++ ){
		n2.push_back (i*i );
	} // end for
	int n;

	while (cin >> n && n ){
		vector <int> m (n-1, 0 );
		rep (i, n-1 ){
			m[i] = n2[i] % n;
		} // end rep
		sort (ALL (m ) );
		m.erase (unique (ALL(m) ), m.end() );
		int size = m.size();
		vector<int> cnt ((n-1)/2+1, 0 );
		int maxd = 0;
		rep (i, size ){
			rep (j, size ){
				if (i == j )
					continue;
				int d = m[i] - m[j];
				if (d < 0 ){
					d += n;
				}// end if
				if (d > (n-1)/2 ){
					d = n - d;
				} // end if
				cnt[d]++;
				maxd = max (d, maxd );
			} // end for
		} // end for
		for (int i = 1; i <= maxd; i++ ){
			cout << cnt[i] << endl;
		} // end for
	} // end loop
		
	return 0;
}

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

using namespace std;

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

int main() {
  for (;;) {
    cin >> n;
    if (!n) break;
    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++)
      cout << results[i] * 2 << endl;
  }
}

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

int n;

int* cnt;

map<int,bool> memo;

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		memo.clear();
		cnt = new int[(n+1)/2];
		for(int i=0; i<(n+1)/2; i++)
			cnt[i] = 0;
		for(int i=1; i<n; i++){
			int tmp = (i*i)%n;
			memo[tmp] = true;
		}
		for(int i=1; i<n-1; i++){
			if(!memo[i])
				continue;
			for(int k=i+1; k<n; k++){
				if(!memo[k])
					continue;
				int tmp = i - k;
				if(tmp < 0)
					tmp += n;
				if(tmp > n/2)
					tmp = n-tmp;
				cnt[tmp]+=2;
			}
		}
		for(int i=1; i<(n+1)/2; i++)
			cout << cnt[i] << endl;
	}
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#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 <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;

int main(){
	int n; 
	while(cin>>n,n){
		vector<int> v(n-1);
		FOR(i,n-1){
			v[i] = (i+1)*(i+1) % n;
		}
		sort(v.begin(),v.end());
		v.erase(unique(v.begin(),v.end()),v.end());

		int n12 = (n-1)/2;
		vector<int> ans(n12+1);
		FOR(i,sz(v)) for(int j = i+1; j < sz(v); j++){
			int df = v[j]-v[i];
			if(df > n12) df = n - df;
			ans[df]++;
		}

		for(int i = 1; i < sz(ans); i++){
			cout << ans[i] * 2<< endl;
		}
	}
	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[1000000]={};
        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 <iostream>
#include <set>
#include <map>
#include <vector>
using namespace std;
int main(void){
  int n;
  while(cin>>n,n){
    set<int> s;
    for(int i=1;i<n;++i){
      s.insert((i*i)%n);
    }
    vector<int> v;
    for(set<int>::iterator it=s.begin();it!=s.end();++it)v.push_back(*it);
    map<int,int> hist;
    for(int i=0;i<v.size();++i){
      for(int j=0;j<v.size();++j){
        int d=v[i]-v[j];
        //cerr<<v[i]<<" "<<v[j]<<endl;
        d=(d<0)?d+n:d;
        d=(d>(n-1)/2)?n-d:d;
        ++hist[d];
      }
    }
    for(int i=1;i<=(n-1)/2;++i){
      cout<<hist[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=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(std::set<int>::iterator 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]);}}