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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		set<int> s;
		repi(i,1,n)
			s.insert(i*i%n);
		vi a(allof(s));
		vi res(n/2+1);
		rep(i,a.size()) rep(j,a.size()){
			if(i==j) continue;
			int temp=a[i]-a[j];
			if(temp<0) temp+=n;
			if(temp>n/2) temp=n-temp;
			res[temp]++;
		}
		repi(i,1,res.size())
			cout<<res[i]<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin >> n, n) {
    set<int> se;
    
    REP(i,n-1){
      se.insert((i+1)*(i+1)%n);
    }
    vector<int> v((n-1)/2);
    FOR(it1,se) {
      FOR(it2,se) {
        if (*it1==*it2) continue;
        int temp = abs(*it1-*it2);
        if (temp > (n-1)/2) temp = n-temp;
        v[temp-1]++;
      }
    }
    
    FOR(it,v) {
      cout << *it << endl;
    }
  }
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main() {
  int n;
  while(cin >> n && n) {
    set<int> st;
    map<int, int> cnt;
    for(int i=0; i<n-1; i++) {
      st.insert( (i+1)*(i+1) % n );
    }
    
    int const size = st.size();
    
    vector<int> vec;
    set<int>::iterator it = st.begin();
    for(it; it!=st.end(); it++) vec.push_back(*it);
    
    for(int i=0; i<size-1; i++) {
      for(int j=i+1; j<size; j++) {
	int temp = vec[i] - vec[j];
	if(temp < 0) { temp += n; }
	if(temp > (n-1)/2) { temp = n - temp; }
	cnt[temp] ++;
      }
    }
    
    for(int i=1; i<=(n-1)/2; i++) {
      cout << cnt[i]*2 << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> v((n+1)/2);
        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());
        for (int i = 0; i < a.size(); ++i) {
            for (int j = 0; j < a.size(); ++j) {
                if(i == j) continue;
                int val = (a[i]-a[j]+n)%n;
                if(val > (n-1)/2) val = n-val;
                v[val]++;
            }
        }
        for (int i = 1; i < v.size(); ++i) {
            printf("%d\n", v[i]);
        }
    }
    return 0;
}

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

signed main() {
	int cnt1[MAX] = {};
	int cnt2[MAX] = {};
	for (int n; cin >> n&&n;) {
		memset(cnt1, 0, sizeof(cnt1));
		memset(cnt2, 0, sizeof(cnt2));
		rep(i, 1, n) {
			cnt1[(i*i) % n]++;
		}
		rep(i, 1, n)cnt1[i] /= 2;
		dumpc(cnt1);
		rep(i, 1, n)rep(j, 1, n) {
			if (i == j)continue;
			if (cnt1[i] && cnt1[j]) {
				int diff = i - j;
				if (diff < 0)diff += n;
				if (diff > (n - 1) / 2)diff = n - diff;
				cnt2[diff]++;
			}
		}
		dumpc(cnt2);
		rep(i, 1, (n - 1) / 2 + 1)cout << cnt2[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main() {
	int ans[5001],m[5001],f[5001],n,i,j,k,c;
	while(cin >> n) {
		if (n==0) break;
		c=0;
		memset(ans,0,sizeof(ans));
		memset(f,0,sizeof(f));
		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 <cstdio>
#include <set>
#include <vector>

using namespace std;

int main(){
  int n;

  while(scanf("%d" ,&n) ,n){
    int MAX = (n-1) / 2;
    int cnt[MAX];
    fill(cnt,cnt+MAX,0);

    set<int> s;
    for(int i = 1 ; i < n ; i++){
      int num = i * i % n;
      if(!s.count(num)){
	s.insert(num);
      }
    }

    set<int>::iterator it;
    vector<int> v;
    for(it = s.begin() ; it != s.end() ; it++){
      v.push_back(*it);
    }

    int len = (int)v.size();
    for(int i = 0 ; i < len ; i++){
      for(int j = 0 ; j < len ; j++){
	if(i == j) continue;
	int diff = v[i] - v[j];

	if(diff < 0){
	  diff += n;
	}
	if(diff > MAX){
	  diff -= n;
	}

	cnt[diff-1]++;
      }
    }
    for(int i = 0 ; i < MAX ; i++){
      printf("%d\n" ,cnt[i]*2);
    }
  }

  return 0;
}