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 <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++){
				if(*it != *it2){
					int a = *it - *it2;
					if(a < 0) a += n;
					if(a > (n - 1) / 2) a = n - a;
					m[a]++;
				}
			}
		}
		for(map<int, int>::iterator it = m.begin(); it != m.end(); it++){
			cout<</*it->fi<<" "<<*/it->se<<endl;
		}
	}
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


typedef set <int> SI;

int B[10001];

int main() {
    int n;
    while ( cin >> n && n ) {
        SI A;
        for ( int i = 1; i < n; ++ i ) {
            A.insert( ( i * i ) % n );
        }
        fill( B, B+10001, 0 );
        for ( SI::iterator it_i = A.begin(); it_i != A.end(); ++ it_i ) {
            for ( SI::iterator it_j = it_i; it_j != A.end(); ++ it_j ) {
                if ( *it_i == *it_j ) continue;
                int sub = *it_i - *it_j;
                if ( sub < 0 ) sub += n;
                if ( sub * 2 > ( n - 1 ) ) sub = n - sub;
                B[sub] ++;
            }
        }
        for ( int i = 1; 2 * i <= n - 1; ++ i ) {
            cout << B[i] * 2 << endl;
        }
    }
    return 0;
}

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

using namespace std;

int main() {
  int n;
  while(cin >> n && n) {
    set<int> st;
    int cnt[10000] = {};
    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 <vector>
#include <algorithm>
#include <set>
#include <cstring>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		bool isAppeared[10001];
		int data[10001];
		set<int> v;
		fill(isAppeared,isAppeared+10001,false);
		fill(data,data+10001,0);
		for(int i = 1; i < n; i++){
			int r=(i*i)%n;
			isAppeared[r]=true;
			v.insert(r);
		}

		for(set<int>::iterator it = v.begin(); it!=v.end(); it++){
			for(set<int>::iterator iit = v.begin(); iit!=v.end(); iit++){
				int ret=*it-*iit;
				if(ret<0)
					ret+=n;
				if(((n-1)/2)<ret){
					ret=n-ret;
				}
				data[ret]++;
			}
		}

		//for(int i = 0; i < n; i++){
		//	for(int j = 0; j < n; j++){
		//		if(isAppeared[i]&&isAppeared[j]){
		//			int ret=i-j;
		//			if(ret<0)
		//				ret+=n;
		//			if(((n-1)/2)<ret){
		//				ret=n-ret;
		//			}
		//			data[ret]++;
		//		}
		//	}
		//}
		for(int i = 1; i <= ((n-1)/2); i++){
			if(data[i]!=0)
				cout<<data[i]<<endl;
		}
	}

	return 0;
}

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

#define f first
#define s second
#define mp make_pair

#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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define MAX 10000

int data[MAX+1];
int s[MAX+1];
int ans[MAX+1];

int main(){
  int n;
  while(scanf("%d",&n),n){
    int cnt = 0;
    memset(ans , 0, sizeof(int) * n);
    memset(data, 0, sizeof(int) * n);
    for(int i=1; i<n; i++){
      int tmp = (i * i) % n;
      if(data[tmp] == 0){
        data[tmp] = 1;
        s[cnt++] = tmp;
      }
    }
    sort(s, s+cnt);
    for(int i=0; i<cnt; i++){
      for(int j=i+1; j<cnt; j++){
        int tmp = s[i] - s[j];
        int tmp2= s[j] - s[i];
        if(tmp  < 0) tmp  += n;
        if(tmp2 < 0) tmp2 += n;
        if(tmp  > (n-1)/2) tmp  = n - tmp;
        if(tmp2 > (n-1)/2) tmp2 = n - tmp2;
        ans[tmp]++; ans[tmp2]++;
      }
    }
    REP(i,(n-1)/2) printf("%d\n",ans[i+1]);
  }
  return 0;
}

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

int main()
{
	int n;
	vector<int> num(5000);
	set<int> a;
	set<int>::iterator it, itr, ite;
	int i, t;

	while (cin>>n, n) {
		a.clear();
		for (i = 1; i < (n-1)/2; i++) num[i] = 0;
 		for (i = 1; i < n; i++) a.insert((i*i)%n);
		ite = a.end();
		ite--;
		for (it = a.begin(); it != ite; it++) {
			itr = it;
			for (itr++; itr != a.end(); itr++) {
				t = *it - *itr;
				if (t < 0) t += n;
				if ((n-1)/2 < t) t = n-t;
				num[t] += 2;
			}
		}
		for (i = 1; i <= (n-1)/2; i++)
			cout<<num[i]<<endl;
	}
	return 0;
}