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++: //15
#include<iostream>
#include<set>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    set<int> sq;
    for(int i=1;i<n;i++){
      sq.insert(i*i%n);
    }
    int ans[10000]={};
    for(set<int>::iterator iti=sq.begin();iti!=sq.end();iti++){
      for(set<int>::iterator itj=sq.begin();itj!=sq.end();itj++){
	if(iti!=itj){
	  int c=*iti-*itj;
	  if(c<0){
	    c+=n;
	  }
	  if(c>(n-1)/2){
	    c=n-c;
	  }
	  ans[c]++;
	}
      }
    }
    for(int i=1;i<=(n-1)/2;i++){
      cout<<ans[i]<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 10001;

int main(void){
    int square[MAX];
    for (int i=1; i < MAX+1; i++) square[i-1] = i*i;
    
    while (true){
        int n;
        cin >> n;
        if (n == 0) break;
        int m = (n-1)/2;
        
        int raw_mod[n-1],mod[n-1];
        for(int i = 0; i < n-1; i++) raw_mod[i] = square[i]%n;

        sort(raw_mod,raw_mod+n-1);
        mod[0] = raw_mod[0];
        int size;
        for(int i = 1, j = 1; i < n-1; i++){
            if (mod[j-1] != raw_mod[i]){
                mod[j] = raw_mod[i];
                j++;
            }
            size = j;
        }

        int hist[MAX] = {};
        for (int i = 0; i < size-1; i++)
            for (int j = i+1; j < size; j++){
                
                int tmp1 = mod[i]-mod[j];
                if (tmp1 < 0) tmp1 += n;
                if (tmp1 > m) tmp1 = n-tmp1;
                
                int tmp2 = mod[j]-mod[i];
                if (tmp2 < 0) tmp2 += n;
                if (tmp2 > m) tmp2 = n-tmp2;
                
                hist[tmp1-1] += 1;
                hist[tmp2-1] += 1;
            }

        for(int i = 0; i < size; i++)
            cout << hist[i] << endl;
    }
    return 0;    
}

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]++;
				tmp = k - i;
				if(tmp < 0)
					tmp += n;
				if(tmp > n/2)
					tmp = n-tmp;
				cnt[tmp]++;
			}
		}
		for(int i=1; i<(n+1)/2; i++)
			cout << cnt[i] << endl;
	}
}

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(){
	vi v(10001,1);
	v[0] = v[1] = 0;
	for(int i=2; i<10001; i++){
		if(v[i] == 1){
			for(int j = i*2; j< 10001; j+=i) v[j] = 0;
		}
	}
	int n;
	while (/*cin >> n*/scanf("%d",&n) != EOF && n > 0) {
		if(n % 4 == 3 && v[n]) {
			for(int i = 0; i<(n-1)/2; i++) printf("%d\n", (n-1)/2 -1);
			continue;	
		}
		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()){
				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;
			printf("%d\n", it->se);
		}
	}
}

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

using namespace std;

int main() {
  
  int N;
  
  while(cin >> N && N) {
    int score[(N-1)/2+5];
    fill(score, score+(N-1)/2+3, 0);
    set<int> st;
    for(int i=1; i<N; i++) {
      st.insert(i*i % N);
    }
    
    vector<int> vec;
    for(set<int>::iterator it = st.begin(); it!=st.end(); it++) {
      vec.push_back(*it);
    }
    
    int const M = st.size();
    
    for(int i=0; i<M; i++) {
      for(int j=0; j<M; j++) {
	if(vec[i] == vec[j]) continue;
	
	int diff = vec[i]-vec[j];
	if(diff < 0) diff += N;
	if((N-1)/2 < diff) {
	  diff = N - diff;
	}
	score[diff] ++;
      }
    }
    
    for(int i=1; i<=(N-1)/2; i++) {
      cout << score[i] << endl;
    }
  }
  
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
 
#define reep(i,a,b) for(long long i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
 
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
    v.assign(a,vector<T>(b,t));
}
 
//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	ll n;
	while(cin>>n,n){
		vector<ll> v(n);
		vector<ll> x((n-1)/2);
		for(ll i=1;i<n;i++){
			v[i]=(i*i)%n;
			// cout<<i<<" "<<v[i]<<endl;
		}
		sort(ALL(v));
		v.erase(unique(ALL(v)),v.end());
		reep(i,1,v.size()){
			// cout<<v[i]<<endl;
			reep(j,1,v.size()){
				if(i==j) continue;
				ll a=v[i]-v[j];
				if(a<0) a+=n;
				if(a>(n-1)/2) a=n-a;
				x[a-1]++;
			}
		}
		rep(i,x.size()){
			cout<<x[i]<<endl;
		}
		// cout<<endl;
	}
}

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

using namespace std;

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

int main() {
  for (int i = 1; i < 10000; i++)
    squares[i] = i * i;
  for (;;) {
    scanf("%i", &n);
    if (!n) return 0;
    memset(results, 0, sizeof results);
    remss.clear();
    memset(remsv, 0, sizeof remsv);
    for (int i = 1; i < n; i++)
      remss.insert(squares[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++)
      printf("%d\n", results[i] * 2);
  }
}