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"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		set<int>aset;
		for (int i = 1; i < N; ++i) {
			int k = (i*i) % N;
			aset.emplace(k);
		}
		vector<int>nums(N);
		for (auto it = aset.begin(); it != aset.end(); ++it) {
			for (auto jt =next( it); jt != aset.end(); ++jt) {
				int sa = *it - *jt;
				if (sa < 0)sa += N;
				if (sa > (N - 1) / 2)sa = N - sa;
				nums[sa]++;
			}
		}
		for (int i = 1; i <= (N - 1) / 2; ++i) {
			cout << nums[i]*2 << 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=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] += 2;
			}
		}

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

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

#define MAX_N 100000

long long q[MAX_N];
long long x[MAX_N];
long long n, z;
vector<long long>p;

int main() {
	while (true) {
		for (int i = 0; i < MAX_N; i++)
		{
			q[i] = 0; x[i] = 0;
		}
		cin >> n;
		p.clear();
		if (n == 0) { break; }
		for (int i = 1; i < n; i++)
		{
			q[(i*i) % n] = 1;
		}
		for (int i = 1; i < n; i++)
		{
			if (q[i] == 1)
			{
				p.push_back(i);
			}
		}
		for (int i = 0; i < p.size(); i++)
		{
			for (int j = i + 1; j < p.size(); j++)
			{
				if (i != j)
				{
					z = p[i] - p[j];
					if (z < 0) { z += n; }
					if (z > (n - 1) / 2) { z = n - z; }
					x[z]++;
				}
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++)
		{
			cout << x[i] * 2 << 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(){
	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()){
				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;
			printf("%d\n", it->se);
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef vector<int> vi;

int main() {
	int n;
	while (cin >> n, n) {
		vi v;
		FOR(i, 1, n) v.push_back((i * i) % n);
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		
		vi ans((n - 1) / 2 + 1, 0);
		REP(i, v.size()) REP(j, v.size()) if (i != j) {
			int x = v[i] - v[j];
			if (x < 0) x += n;
			if (x > (n - 1) / 2) x = n - x;
			ans[x]++;
		}
		FOR(i, 1, (n - 1) / 2 + 1) printf("%d\n", ans[i]);
		
	}
	return 0;
}

C++: #include <set>
#include <cstdio>
int i,n,v[9999];main(){for(;scanf("%d",&n),n;){std::set<int>t;for(i=1;i<n;i++)v[i]=0,t.insert(i*i%n);for(auto s=t.begin(),S=s;s!=t.end();s++)for(S=s;++S!=t.end();v[i>n/2?n-i:i]+=2)i=*S-*s;for(i=1;i<=n/2;i++)printf("%d\n",v[i]);}}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main()
{
  int ans[1000000],n; 
  while(cin >> n,n)
    {
      vector<int> vec;
      rep(i,(int)((n-1)/2)+1)ans[i] = 0;
      REP(i,1,n)vec.push_back((i*i)%n);
      sort(vec.begin(),vec.end()); 
      vec.erase(unique(vec.begin(),vec.end()),vec.end());
      rep(i,vec.size())
	{
	  rep(j,vec.size())
	    {
	      int diff = vec[i] - vec[j];
	      if(diff < 0)diff += n;
	      if(diff > (n-1)/2)diff = n - diff;
	      if(1 <= diff && diff <= (n-1)/2)ans[diff]++;
	    }
	}
      REP(i,1,(int)((n-1)/2)+1)cout << ans[i] << endl;
    }
  return 0;
}

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

int main(){
	int n;
	while( cin >> n , n ){
		vector<int> v;
		int h[10000] = {0};
		
		for(int i=1 ; i < n ; i++ ){
			int a = (i * i) % n;
			if( count(v.begin() , v.end() , a ) == 0 ){
				v.push_back( a );
			}
		}
		for(int i=0 ; i < v.size() ; i++ ){
			for(int j=0 ; j < v.size() ; j++ ){
				if( i == j ) continue;
				
				int c = v[i] - v[j];
				if( c < 0 ) c += n;
				if( ((n-1)/2) < c ) c = n - c;
				h[c]++; 
			}
		}
		for(int i=1 ; i <= (n-1)/2 ; i++ ){
			cout << h[i] << endl;
		}
	}
}

C++: #include <iostream>

using namespace std;

void calc(int n);

int main(void){
  int n;
  while(true){
    cin>>n;
    if(n==0){break;}
    calc(n);
  }
  return 0;
}

void calc(int n){
  int mod[n];
  for(int i=0;i<n;i++){
    mod[i]=0;
  }
  for(int i=1;i<n;i++){
    mod[(i*i)%n]=1;
  }
  int retval[1+n/2];
  for(int i=0;i<=n/2;i++){
    retval[i]=0;
  }
  for(int i=0;i<n;i++){
    if(mod[i]==0){
      continue;
    }
    for(int j=i+1;j<n;j++){
      if(mod[j]==0){
        continue;
      }
      int d=j-i;
      if(d<0){
        d+=n;
      }
      if(d>n/2){
        d=n-d;
      }
      retval[d]++;
    }
  }
  for(int i=1;i<=n/2;i++){
    cout<<retval[i]*2<<endl;
  }
}