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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n;
V v1,v2;

int main(){
	while (cin >> n&&n){
		FOR(i, 1, n){
			ll k = i*i % n;
			if (find(ALL(v1), k) == v1.end()){
				v1.push_back(k);
			}
		}
		REP(i, v1.size()){
			REP(j, v1.size()){
				if (i != j){
					ll k = v1[i] - v1[j];
					if (k < 0)k += n;
					if (k > (n - 1) / 2)k = n - k;
					v2.push_back(k);
				}
			}
		}
		sort(ALL(v2));
		FOR(i, 1, (n - 1) / 2 + 1){
			cout << upper_bound(ALL(v2), i) - lower_bound(ALL(v2), i) << endl;
		}
		v1.clear();
		v2.clear();
	}
}

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

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

using namespace std;

int main()
{
	int n;
	double n2;
		
	while(cin >> n && n)
	{
		n2 = (n-1)/2;

		vector<int> v;
		REP(i,1,n)
		{
			int temp = i*i;
			temp %= n;
			
			vector<int>::iterator ite = find(v.begin(),v.end(),temp);
			if(ite == v.end())
			{
				v.push_back(temp);
			}
		}

		map<int,int> m;
		rep(i,v.size())
		{
			REP(j,i+1,v.size())
			{
				int ans = v[i] - v[j];
				if(ans < 0) ans += n;
				if(ans > n2) ans = n - ans;
				m[ans]++;
			}
		}
		
		REP(i,1,n2+1)
		{
			cout << m[i]*2 << 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[3000];
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 <set>
#include <algorithm>

using namespace std;


int main(void)
{
	int n;
	set<int> target;
	int data[10000];
	int change[10000];

	while( cin >> n && n != 0 ){
		target.clear();
		for( int i = 0;i < 10000;i++ ) change[i] = data[i] = 0;
		for( int i = 1;i < n;i++ ){
			target.insert( i * i % n );
		}

		copy( target.begin(), target.end(), change );
		

		int hoge = ( n - 1 ) / 2;
		for( int *it = change;it != change + hoge;it++ ){
			for( int *it2 = change;it2 != change + hoge;it2++ ){
				if( it == it2 ) continue;
				int answer = *it - *it2;
				while( 1 ){
					if( answer < 0 ){ answer += n; continue; }
					else if( answer > hoge ){ answer = n - answer; continue; }
					data[answer]++;
					break;
				}
			}
		}

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

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,number[10001];
    for(int i=1;i<10000;i++)number[i]=i*i;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(number[i]%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[5000]={};
        for(int i=0;i<num.size();i++){
            for(int j=0,k;j<num.size();j++){
                k=num[i]-num[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 <bits/stdc++.h>
using namespace std;

void solve(int n){
  vector <int> num;
  for(int i=1;i<n;i++)num.push_back(i*i%n);
  sort(num.begin(),num.end());
  num.erase(unique(num.begin(),num.end()),num.end());
  
  int used[10001]={};
  for(int i=0;i<num.size();i++){
    for(int j=0;j<num.size();j++){
      if(i==j)continue;
      int a=num[i]-num[j];
      if(a<0)a+=n;
      if((n-1)/2<a)a=n-a;
      used[a]++;
    }
  }
  for(int i=1;i<=(n-1)/2;i++)cout << used[i]<<endl;
}

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

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
typedef long long int Int;

int main() {
  Int N;
  while(cin >>N && N){
    set<Int> S;
    FOR(i, 1, N) S.insert((i * i) % N);
    vector<Int> v(S.begin(), S.end()), cnt((N - 1) / 2 + 1, 0);
    REP(i, v.size()){
      REP(j, v.size()){
        if(i == j) continue;
        int n = v[i] - v[j];
        if(n < 0) n += N;
        if(n > (N - 1) / 2) n = N - n;
        cnt[n]++;
      }
    }
    FOR(i, 1, cnt.size()) cout <<cnt[i] <<endl;
  }
  return 0;
}