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*/scanf("%d",&n) != EOF && 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()){
				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 <iostream>
#include <cstdio>
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
int main(){
  ll n;
  while(cin >> n,n){
    vector<ll>ve;
    map<ll,ll>mp,ans;
    for(int i = 1 ; i*2 < n ; i++ ){
      if(mp[(i*i)%n] == 0)ve.push_back((i*i)%n);
      mp[(i*i)%n] = 1;
    }
    sort(ve.begin(),ve.end());
    vector<ll>::iterator a =  ve.begin(),b;
    for(; a != ve.end() ; a++ ){
      for(b = a; b != ve.end() ; b++ ){
	if(*b == *a)continue;
	if(((*b) - (*a)) > (n-1)/2 ){
	  ans[(n - (*b) + (*a))]+=2;
	} else {
	  ans[(*b) - (*a)]+=2;
	}
      }
    }
    map<ll,ll>::iterator it =  ans.begin();
    for(; it != ans.end() ; it++)if((*it).first != 0)cout << (*it).second << endl;
  }
  return 0;
}

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

int n;
int* cnt, *use;
int p;
map<int,bool> memo;

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		memo.clear();
		p=0;
		cnt = new int[(n+1)/2];
		use = new int[n];

		for(int i=0; i<(n+1)/2; i++)
			cnt[i] = 0;

		for(int i=1; i<n; i++){
			int tmp = i*i%n;
			if(memo[tmp])
				continue;
			memo[tmp] = true;
			use[p++] = tmp;
		}

		for(int i=0; i<p-1; i++){
			for(int k=i+1; k<p; k++){
				int tmp = use[i]-use[k];
				if(tmp<0)
					tmp += n;
				if(tmp>(n-1)/2)
					tmp = n-tmp;
				cnt[tmp]++;
				tmp = use[k]-use[i];
				if(tmp<0)
					tmp += n;
				if(tmp>(n-1)/2)
					tmp = n-tmp;
				cnt[tmp]++;
			}
		}

		for(int i=1; i<(n+1)/2; i++)
			cout << cnt[i] << endl;

		delete[] cnt;
		delete[] use;
	}
}

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

using namespace std;

int main() {
	int ans[5001],m[10001],f[10001],n,i,j,k,c;
	while(cin >> n) {
		if (n==0) break;
		c=0;
		for (i=0;i<10001;i++) ans[i]=f[i]=0;
		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<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; 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;
}

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

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    set<int> sqmod;
    for(int i = 1; i < N; ++i)
      sqmod.insert((i*i)%N);
    // sort(begin(sqmod), end(sqmod));
    // sqmod.erase(unique(begin(sqmod), end(sqmod)), end(sqmod));
    vector<int> cnt((N - 1) / 2 + 1, 0);
    for(int i : sqmod) {
      for(int j : sqmod) {
        if(i == j) continue;
        int diff = i - j;
        if(diff < 0) diff += N;
        if(diff > (N - 1)/2) diff = N - diff;
        cnt[diff]++;
      }
    }
    for(int i = 1; i < (int)cnt.size(); ++i) {
      cout << cnt[i] << endl;
    }
  }
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int main() {
	while(scanf("%d", &n), n) {
		vector<int> v1, v2;
		for(int i = 1; i < n; i++) v1.push_back(i * i % n);
		sort(v1.begin(), v1.end());
		v2.push_back(v1[0]);
		for(int i = 1; i < v1.size(); i++) {
			if(v1[i - 1] != v1[i]) v2.push_back(v1[i]);
		}
		vector<int> a(n / 2);
		for(int i = 0; i < v2.size(); i++) {
			for(int j = i + 1; j < v2.size(); j++) {
				int r = v2[j] - v2[i];
				if(r < 0) r += n;
				if(r > n / 2) r = n - r;
				a[r - 1]++;
			}
		}
		for(int i = 0; i < n / 2; i++) printf("%d\n", a[i] * 2);
	}
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int p[10000],c[9999],n;
  r(i,10000)p[i]=i*i;
  while(cin>>n,n){
    memset(c,0,sizeof(c));
    vector<int>v;
    r(i,n-1)v.push_back(p[i+1]%n);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    r(i,v.size())r(j,i)if(i!=j){
      int x=v[i]-v[j];
      if(x<0)x+=n;
      else if(x>(n-1)/2)x=n-x;
      c[x]+=2;
    }
    r(i,(n-1)/2)cout<<c[i+1]<<endl;
  }
}