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<bits/stdc++.h>
using namespace std;
#define N_MAX 10000
int main()
{
  
  int n, fact[N_MAX + 1];
  bool prime[N_MAX + 1] = {};
  set< int > digit;

  int mul[N_MAX * 1];

  for(int i = 1; i <= N_MAX; i++){
    fact[i] = i * i;
  }

  while(cin >> n, n){
    fill_n( mul, n + 1, 0);

    for(int i = 1; i< n; i++){
      digit.insert(fact[i] % n);
    }
    for(__typeof digit.begin() it = digit.begin(); it != digit.end(); it++){
      for(__typeof digit.begin() iitt = digit.begin(); iitt != digit.end(); iitt++){
        if(it == iitt) continue;

        int calc = *it - *iitt;
        if(calc < 0) calc += n;
        if((n - 1) / 2 < calc) calc = n - calc;
        mul[calc]++;
      }
    }

    for(int i = 1; i <= (n - 1) / 2; i++){
      printf("%d\n", mul[i]);
    }
    digit.clear();
  }
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

inline int calcDiff(int limit, int n, int a, int b){
	int result = a - b;
	if(result < 0){ result += n; }
	if(result > limit){ result = n - result; }
	return result;
}

int main(){
	while(true){
		int n;
		scanf("%d", &n);
		if(n == 0){ break; }
		vector<int> numbers;
		for(int i = n - 1; i > 0; --i){ numbers.push_back(i * i % n); }
		sort(numbers.begin(), numbers.end());
		numbers.erase(unique(numbers.begin(), numbers.end()), numbers.end());
		int limit = (n - 1) / 2;
		vector<int> answers(limit + 1, 0);
		for(int i = numbers.size() - 1; i >= 0; --i){
			for(int j = i - 1; j >= 0; --j){
				answers[calcDiff(limit, n, numbers[i], numbers[j])] += 2;
			}
		}
		for(int i = 1; i <= limit; ++i){
			printf("%d\n", answers[i]);
		}
	}
	return 0;
}

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

using namespace std;

const int N = 10000;
int cnt[N] = { 0 }, ans[N / 2 + 1] = { 0 };

int main(){
	int n;
	while(cin >> n, n) {
		// memset(cnt, 0, sizeof(cnt));
		memset(ans, 0, sizeof(ans));
		set<int> k;
		for(int i = 1;i < n;++i){
			int a = i % n;
			int v = (a * a) % n;
			// cnt[v]++;
			k.insert(v);
		}
		for(auto f = k.begin();f != k.end();++f){
			for(auto b = next(f, 1);b != k.end();++b){
				int diff = (*b - *f);
				// cout << "diff : " << diff << endl;
				if(diff > (n - 1) / 2) {
					diff = n - diff;
				}
				ans[diff] += 2;
			}
		}
		for(int i = 1;i <= (n - 1) / 2;++i){
			cout << ans[i] << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const int INF = 1000000;
const int mod = 1e9 + 7;



int main(){
	int n;
	while (cin >> n && n > 0) {
		set<int> s;
		map<int, int> m;
		for(int i = 1; i < n; i++) s.insert(i * i % n);
		//for(auto it :s) cout<<it<<endl;
		for(set<int>::iterator it = s.begin(); it != s.end(); ++it){
			//for(set<int>::iterator it2 = s.begin(); it2 != s.end(); it2++){
			set<int>::iterator it2 =it;
			++it2;
			while(it2 != s.end()){
				if(*it != *it2){
					int a = *it - *it2;
					if(a < 0) a += n;
					if(a > (n - 1) / 2) a = n - a;
					m[a] += 2;
					++it2;
				}
			}
		}
		for(map<int, int>::iterator it = m.begin(); it != m.end(); ++it){
			cout<</*it->fi<<" "<<*/it->se<<endl;
		}
	}
}

C++: //Nature of Prime Numbers
#include <stdio.h>
#include <string.h>
#include <set>

int main(){
  int n;
  while(1){
    scanf("%d", &n);
    if(n == 0){
      break;
    }
    std::set<int> S;
    int A[n / 2 + 1];
    memset(A, 0, sizeof(A));
    for(int i = 1; i < n; ++i){
      S.insert(i * i % n);
    }
	for(std::set<int>::iterator a = S.begin();a != S.end(); ++a){
      for(std::set<int>::iterator b = S.begin();b != S.end(); ++b){
        if(a == b){
          continue;
        }
        int c = *a - *b;
        if(c < 0){
          c = c + n;
        }
        if(c > (n - 1) / 2){
          c = n - c;
        }
        A[c]++;
      }
    }
    for(int i = 1; i <= (n - 1) / 2; ++i){
      printf("%d\n", A[i]);
    }
  }    
  return 0;
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int main()
{
  int n;
  while (n = in()){
    vector<int> v;
    vector<int> counter(n + 1, 0);
    lep(i, n - 1) v.push_back(i * i % n);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    rep(i, v.size()){
      rep(j, v.size()){
        if (i == j) continue;
        int x = v[i] - v[j];
        if (x < 0) x += n;
        if (x > (n - 1) / 2) x = n - x;
        counter[x]++;
      }
    }
    lep(i, (n - 1) / 2){
      printf("%d\n", counter[i]);
    }
  }
  return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int nums[16384], ans[8192];
	int i, j, n, size, half;
	
	while(scanf("%d", &n), n){
		size = 0;
		half = (n-1) / 2;
		for(i=1; i<n; ++i)
			nums[size++] = (i*i) % n;

		sort(nums, nums + size);
		size = unique(nums, nums + size) - nums;

		memset(ans, 0, (half+1)*4);
		for(i=0; i<size; ++i){
			for(j=0; j<i; ++j){
				int p = abs(nums[i]-nums[j]);
				if(p>half) p = n - p;
				++ans[p];
			}
		}
		for(i=1; i<=half; ++i)
			printf("%d\n", ans[i]*2);
	}

	return 0;
}

C++: #include <stdio.h>
#include <set>
#include <vector>
using namespace std;
const int N=1e4+10;
#define PB push_back
int abs(int n){return n>0?n:-n;}
int main(){
    int n,a[N],mid,temp;
    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){
            temp=abs(v[j]-v[i]);
            if(temp>mid)a[n-temp]++;
            else a[temp]++;
        }
        for(int i=1;i<=mid;i++)printf("%d\n",a[i]);
    }
}