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 <cstdio>
#include <cstring>

int n;
int cnt[10001],cnt2[10001];;

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(cnt,0,sizeof(cnt));
		memset(cnt2,0,sizeof(cnt2));
		for(int i=1;i<n;i++){
			cnt[i*i%n]++;
		}
		for(int i=1;i<n;i++){
			for(int j=1;j<n;j++){
				if(cnt[i]>0 && cnt[j]>0){
					int a=i-j;
					if(a<0)a+=n;
					if(a>(n-1)/2)a=n-a;
					cnt2[a]++;
				}
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			printf("%d\n",cnt2[i]);
		}
	}
	return 0;
}

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

#define MAX_N 100000

long long q[MAX_N];
long long x[MAX_N];
long long n;
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]++;
		}
		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 = 0; j < p.size(); j++) {
				long long z;
				z = abs(n * n + p[i] - p[j]) % n;
				if (z > n / 2) { z = n - z; }
				x[z]++;
			}
		}
		for (int i = 1; i <= n / 2; i++) {
			cout << x[i] << endl;
		}
	}
}

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

int n, T[MAX+1];

void solve(){
  vector<int> S;
  for ( int i = 1; i <= (n-1)/2; i++ ) T[i] = 0;
  for ( int i = 1; i <= n-1; i++ ) S.push_back((i*i)%n);
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  for ( int i = 0; i < S.size(); i++ ){
    for ( int j = 0; j < S.size(); j++ ){
      if ( i == j ) continue;
      int d = S[j] - S[i];
      if ( d < 0 ) d += n;
      if ( d > (n-1)/2 ) d = n-d;
      T[d]++;
    }
  }
  for ( int i = 1; i <= (n-1)/2; i++ ) cout << T[i] << endl;
}

main(){
  while(1){
    cin >> n;
    if ( n == 0 ) break;
    solve();
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int number[10001];
    for(int i=1;i<10000;i++)number[i]=i*i;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(number[i]%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[10001]={};
        for(int i=0;i<num.size();i++){
            for(int j=0,k;j<num.size();j++){
                k=num[i]-num[j];
                if(k<0)k+=n;
                if(k>n/2)k=n-k;
                ans[k]++;
            }
        }
        for(int i=1;i<=n/2;i++)cout<<ans[i]<<endl;
    }
}

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

using namespace std;

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

int main() {
  for (;;) {
    cin >> n;
    if (!n) break;
    memset(results, 0, sizeof results);
    remss.clear();
    remsv.clear();
    for (int i = 1; i < n; i++)
      remss.insert(i * i % n);
    copy(remss.begin(), remss.end(), back_inserter(remsv));
    for (int i = 0; i < remsv.size()-1; i++)
      for (int j = i+1; j < remsv.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++)
      cout << results[i] * 2 << endl;
  }
}

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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		unordered_set<int>se;
		for (int i = 1; i < n; i++)se.insert(i*i%n);
		unordered_map<int, int>mp;
		for (auto i = se.begin(); i != se.end(); i++) {
			for (auto j = se.begin(); j != se.end(); j++) {
				if (i == j)continue;
				int d = *i - *j;
				if (d < 0)d += n;
				if (d > (n - 1) / 2) d -= n;
				mp[abs(d)]++;
			}
		}
		for (auto p : mp)printf("%d\n", p.second);
	}
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        set<int> remains;
        for (int i = 1; i < n; i++) {
            int remain = (i * i) % n;
            remains.insert(remain);
        }
        int max = (n - 1) / 2;
        int* differences = new int [max + 1];
        fill_n(differences, max + 1, 0);
        for (set<int>::iterator it1 = remains.begin(); it1 != remains.end(); it1++) {
            for (set<int>::iterator it2 = remains.begin(); it2 != remains.end(); it2++) {
                if (it1 == it2) {
                    continue;
                }
                int diff = *it1 - *it2;
                if (diff < 0) {
                    diff += n;
                }
                if (diff > max) {
                    diff = n - diff;
                }
                differences[diff]++;
            }
        }
        for (int i = 1; i <= max; i++) {
            cout << differences[i] << endl;
        }
        delete[] differences;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n, a[20000];
	
	bool exist[20000];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i <= n; i++){
			exist[i] = false;
			a[i] = 0;
		}
		
		for(int i = 1; i < n; i++){
			exist[(i * i) % n] = true;
		}
		
		int dummy;
		
		for(int i = 1; i < n; i++){
			for(int j = 1; j < n; j++){
				if(i == j){
					continue;
				}
				if(exist[i] && exist[j]){
					dummy = i - j;
					if(dummy < 0){
						dummy += n;
					}
					if(dummy > (n - 1) / 2){
						dummy = n - dummy;
					}
					a[dummy]++;
				}
			}
		}
		
		for(int i = 1; i <= n / 2; i++){
			printf("%d\n", a[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(std::set<int>::iterator 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;i++)printf("%d\n",v[++i]);}}

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

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		
		std::set<int> rem;
		for (int i=1; i<=n/2; i++) {
			rem.insert((i*i)%n);
		}
		std::vector<int> v(n/2);
		for (std::set<int>::iterator it1 = rem.begin(); it1 != rem.end(); ++it1) {
			int a = *it1;
			for (std::set<int>::iterator it2 = rem.begin(); it2 != rem.end(); ++it2) {
				if (it1 == it2) continue;
				int b = *it2;
				int d = a-b;
				if (d<0) d += n;
				if (d>n/2) d = n - d;
				v[d-1]++;
			}
		}
		for (int i=0; i<n/2; i++) std::cout << v[i] << std::endl;
	}
		
	return 0;
}