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++: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        map<int, bool> m;
        for(int i = 1; i < n; i++){
            m[(i * i) % n] = true;
        }
        vector<int> v;
        for(pair<int, bool> p : m){
            v.push_back(p.first);
        }
        int cnt[11000] = {};
        for(int i = 0; i < v.size(); i++){
            for(int j = 0; j < v.size(); j++){
                if(i == j){
                    continue;
                }
                int num = v[i] - v[j];
                if(num < 0){
                    num += n;
                }
                if(num > (n - 1) / 2){
                    num = n - num;
                }
                cnt[num] += 1;
            }
        }
        for(int i = 1; i <= (n - 1) / 2; i++){
            cout << cnt[i] << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int n;

set<int> si;
set<int>::iterator it, it2;

int main(){
	while (cin >> n&&n){
		int cnt[10000] = {};
		FOR(i, 1, n){
			si.insert((i*i) % n);
		}
		for (it = si.begin(); it != si.end(); it++){
			for (it2 = si.begin(); it2 != si.end(); it2++){
				if (it == it2)continue;
				int num = *it - *it2;
				if (num < 0)num += n;
				if (num > (n - 1) / 2)num = n - num;
				cnt[num]++;
			}
		}
		FOR(i, 1, (n - 1) / 2 + 1){
			cout << cnt[i] << endl;
		}
		si.clear();
	}
}

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,T=t.end();s!=T;S=++s)for(;++S!=T;v[i>n/2?n-i:i]+=2)i=*S-*s;for(i=0;i<n/2;)printf("%d\n",v[++i]);}}

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

using namespace std;


int main(void)
{
	int n;
	set<int> target;
	int data[10000];
	int change[20000];

	while( cin >> n && n != 0 ){
		target.clear();
		for( int i = 0;i < 10000;i++ ) data[i] = 0;
		for( int i = 0;i < 20000;i++ ) change[i] = 0;
		for( int i = 1;i < n;i++ ){
			target.insert( i * i % n );
		}

		for( set<int>::iterator it = target.begin();it != target.end();it++ ){
			for( set<int>::iterator it2 = target.begin();it2 != target.end();it2++ ){
				int answer = *it - *it2;
				if( change[answer + 10000] != 0 ){ data[change[answer + 10000]]++; continue; }
				while( 1 ){
					if( answer < 0 ){ answer += n; continue; }
					else if( answer > ( n - 1 ) / 2 ){ answer = n - answer; continue; }
					data[answer]++;
					break;
				}
			}
		}

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

	return 0;
}

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

using namespace std;

int main()
{
  int n;
  while(cin >> n, n){
    int m = (n-1) / 2;
    bool sq[10001] = {false};
    int a[5001] = {0};
    for(int i = 1; i < n; i++) sq[(i*i)%n] = true;
    for(int i = 0; i < n; i++){
      if(!sq[i]) continue;
      for(int j = 0; j < n; j++){
	if(i == j) continue;
	if(!sq[j]) continue;
	int d = i - j;
	if(d < 0){
	  if(d + n > m) a[n-(d+n)]++;
	  else a[d+n]++;
	} else {
	  if(d > m) a[n-d]++;
	  else a[d]++;
	}
      }
    }
    for(int i = 1; i <= m; i++) cout << a[i] << endl;
  }
  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,T=t.end();s!=T;S=++s)for(;++S!=T;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 <vector>
#include <algorithm>
#include <set>

#define MAX_N 10000

using namespace std;

int prime[MAX_N];
bool is_prime[MAX_N + 1];
bool is_p[MAX_N + 1];
vector<int> prime2;
int data[MAX_N];
set<int> used;

int sieve(int n){
  int p = 0;
  for(int i=0;i<=n;i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      prime[p++] = i;
      for(int j=2*i;j<=n;j+=i) is_prime[j] = false;
    }
  }
  return p;
}

void solve(int n){
  int size = (n-1)/2;
  /*if(is_p[n]){
    for(int i=0;i<size;i++){
      cout << size-1 << endl;
    }
    return;
    }*/
  fill(data, data+size, 0);
  used.clear();
  for(int i=1;i<=size;i++){
    int tmp = (i*i)%n;
    used.insert(tmp);
  }
  set<int>::iterator ite = used.begin();
  for(;ite!=used.end();ite++){
    for(set<int>::iterator ite2 = used.begin();ite2!=used.end();ite2++){
      if(ite == ite2) continue;
      int a = *ite;
      int b = *ite2;
      int c = a-b;
      if(c < 0) c += n;
      if(c > size) c = n - c;
      ++data[c-1];
    }
    }
  for(int i=0;i<size;i++){
    cout << data[i] << endl;
  }
}

main(){
  int size = sieve(MAX_N);
  for(int i=0;i<size;i++){
    if(prime[i] % 4 == 3){
      prime2.push_back(prime[i]);
      is_p[prime[i]] = true;
    }
  }
  int n;
  while(cin >> n && n){
    /*if(n == 1){
      cout << 0 << endl;
      continue;
      }*/
    solve(n);
  }
  return 0;
}

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

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

	while (cin>>n, n) {
		a.clear();
		for (i = 0; i < 20000; 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;
}