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 <vector>
#include <cstring>
#include <iostream>
using namespace std;
int n, c, a[10000]; bool p[10000], prime[10000];
int main() {
	for(int i = 2; i < 10000; i++) prime[i] = true;
	for(int i = 2; i * i < 10000; i++) {
		if(!prime[i]) continue;
		for(int j = i * i; j < 10000; j += i) prime[j] = false;
	}
	while(scanf("%d", &n), c = 0, n) {
		if(prime[n] && n % 4 == 3) {
			for(int i = 0; i < n / 2; i++) printf("%d\n", (n - 3) / 2);
			continue;
		}
		vector<int> v;
		for(int i = 0; i < n; i++) a[i] = 0, p[i] = 0;
		for(int i = 1; i < n; i++) p[i * i % n] = true;
		for(int i = 0; i < n; i++) {
			if(p[i]) v.push_back(i);
		}
		for(int i = 0; i < v.size(); i++) {
			for(int j = i + 1; j < v.size(); j++) {
				int r = v[j] - v[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"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    int n;
    while(cin>>n&&n){
        set<int> a;
        map<int,int> b;
        for(int i=1;i<n;i++){
            int tmp = 0;
            tmp = i*i;
            tmp %= n;
            a.insert(tmp);
        }
        
        
        vector<int> vec;
        for(int x : a) vec.pb(x);
        
        rep(i,vec.size()){
            rep(j,vec.size()){
                if(i==j)continue;
                int tmp = vec[i]-vec[j];
                while(1){
                    int m = tmp;
                    if(tmp<0)tmp+=n;
                    if(tmp>(n-1)/2)tmp = n-tmp;
                    if(m==tmp)break;
                }
//                cout<<tmp<<endl;
                b[tmp] = b[tmp]+1;
            }
        }
        for(pii x : b){
            cout<<x.second<<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 main() {
    int n;
    while ( cin >> n && n ) {
        SI A;
        for ( int i = 1; i < n; ++ i ) {
            A.insert( ( i * i ) % n );
        }
        map <int, int> B;
        for ( SI::iterator it_i = A.begin(); it_i != A.end(); ++ it_i ) {
            for ( SI::iterator it_j = A.begin(); 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; i <= ( n - 1 ) / 2; ++ i ) {
            cout << B[i] << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <set>
#include <map>
#include <vector>
using namespace std;
int main(void){
  int n;
  while(cin>>n,n){
    set<int> s;
    for(int i=1;i<n;++i){
      s.insert((i*i)%n);
    }
    vector<int> v;
    for(set<int>::iterator it=s.begin();it!=s.end();++it)v.push_back(*it);
    map<int,int> hist;
    for(int i=0;i<v.size();++i){
      for(int j=v.size()-1;j>i;--j){
        int d=v[i]-v[j];
        //cerr<<v[i]<<" "<<v[j]<<endl;
        d=(d<0)?d+n:d;
        d=(d>(n-1)/2)?n-d:d;
        ++hist[d];
      }
    }
    for(int i=1;i<=(n-1)/2;++i){
      cout<<hist[i]*2<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int n;
bool is_nijo[10001];
vector <int> a;


void sieve2() {
  for(int i=1;i<n;i++) {
    is_nijo[i] = false;
  }
  for(int i=1;i<n;i++) {
    is_nijo[(i * i) % n] = true;
  }
  for(int i=1;i<n;i++) {
    if(is_nijo[i]) {
      a.push_back(i);
    }
  }
}

int main() {
  while(cin >> n) {
    if(n==0) break;
    sieve2();
    int b[10001] = {};
    while(!a.empty()) {
      int temp = a[a.size()-1];a.pop_back();
      for(unsigned int i=0;i<a.size();i++) {

	if(0 <=temp - a[i] && temp - a[i] <= (n-1)/2) {
	  b[temp-a[i]]++;
	}
	else if(temp - a[i] < 0) {
	  if(temp-a[i]+n <= (n-1)/2) {
	    b[temp-a[i]+n]++;
	  }
	  else {
	    b[a[i]-temp]++;
	  }
	}
	else if(temp - a[i] > (n-1)/2) {
	  b[n-temp+a[i]]++;
	}


	if(0 <=a[i] - temp && a[i] - temp <= (n-1)/2) {
	  b[a[i] - temp]++;
	}
	else if(a[i] - temp < 0) {
	  if(a[i] - temp+n <= (n-1)/2) {
	    b[a[i] - temp+n]++;
	  }
	  else {
	    b[temp - a[i]]++;
	  }
	}
	else if(a[i] - temp > (n-1)/2) {
	  b[n-a[i]+temp]++;
	}

      }
    }
    if(n != 3) {    
      for(int i=1;i<=(n-1)/2;i++) {
	cout << b[i] << endl;
      }
    }
    else {
      cout << 1 << endl;
    }
  }
}

C++: #include <stdio.h>
#include <set>
#include <vector>
using namespace std;
const int N=1e5+10;
#define PB push_back
int main(){
    int n,a[N],mid;
    set<int> s;
    vector<int> v;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        s.clear();
        v.clear();
        for(int i=1;i<n;i++)s.insert((i*i)%n);
        mid=n>>1;
        for(int i=0;i<=mid;i++)a[i]=0;
        for(int i:s)v.PB(i);
        for(int i=0;i<v.size();i++)for(int j=0;j<v.size();j++)if(i!=j){
            if(v[j]-v[i]>mid)a[n-(v[j]-v[i])]++;
            else a[v[j]-v[i]]++;
        }
        for(int i=1;i<=mid;i++)printf("%d\n",a[i]*2);
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int cnt[5010];
int main(){
  int n;
  while(cin>>n&&n){
    set<int> st;
    vector<int> v;
    for(int i=1;i<n;i++){
      st.insert(i*i%n);
    }
    set<int>::iterator it=st.begin();
    while(it!=st.end()){
      v.push_back(*it);
      ++it;
    }
    for(int i=0;i<=(n-1)/2;i++)cnt[i]=0;
    for(int i=0;i<v.size();i++){
      for(int j=i+1;j<v.size();j++){
	int x=v[j]-v[i];
	x=min(x,n-x);
	cnt[x]+=2;
      }
    }
    for(int i=1;i<=(n-1)/2;i++)cout<<cnt[i]<<endl;
  }
  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n, c[10000];
  while (true) {
    cin >> n;
    if (n == 0) break;
    vector<int> a;
    rep (i, n - 1) a.push_back((i + 1) * (i + 1) % n);
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    rep (i, n) c[i] = 0;
    rep (i, a.size()) rep (j, a.size()) if (i != j) {
      int k = a[i] - a[j];
      if (k < 0) k += n;
      if (k > (n - 1) / 2) k = n - k;
      ++c[k];
    }
    rep (i, (n - 1) / 2) cout << c[i + 1] << endl;
  }
}