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<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-9
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;
int main(){
    int n;
    while(scanf("%d",&n),n){
        bool flg[12800]={0};
        vector < int > numbers;
        map <int,int> cnt;
        reps(i,1,n/2+1){
            int tmp = (i*i)%n;
            if(flg[tmp]++)continue;
            numbers.PB(tmp);
        }
        int len = numbers.size();
        sort(numbers.begin(),numbers.end());
        rep(i,len){
            reps(j,i+1,len){
                int tmp = numbers[j]-numbers[i];
                if(tmp > (n-1)/2)tmp = n-tmp;
                cnt[tmp]++;
            }
        }
        map <int,int> :: iterator it;
        for(it = cnt.begin(); it != cnt.end(); it++){
            cout << 2*it->se << endl;
        }
    }
    return 0;
}

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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		set<int>se;
		for (int i = 1; i < n; i++)se.insert(i*i%n);
		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 <vector>
#include <algorithm>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		set<int> Set;
		for(int i = 1; i < n; ++i)
		{
			Set.insert((i * i) % n);
		}
		vector<int> num;
		set<int>::iterator it = Set.begin();
		while(it != Set.end())
		{
			num.push_back(*it);
			++it;
		}
		vector<int> diff;
		for(int i = 0; i < num.size(); ++i)
		{
			for(int j = 0; j < num.size(); ++j)
			{
				if(i == j)
				{
					continue;
				}
				int temp = num[i] - num[j];
				if(temp < 0)
				{
					temp += n;
				}
				if(temp > (n - 1) / 2)
				{
					temp = n - temp;
				}
				diff.push_back(temp);
			}
		}
		sort(diff.begin(), diff.end());
		int now = diff[0];
		int count = 1;
		for(int i = 1; i < diff.size(); ++i)
		{
			if(diff[i] != now)
			{
				cout << count << endl;
				now = diff[i];
				count = 1;
			}
			else
			{
				++count;
			}
		}
		if(count >= 2)
		{
			cout << count << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(i*i%n);
        sort(num.begin(),num.end());
        vector<int> number;
        number.push_back(num[0]);
        for(int i=1;i<num.size();i++)if(num[i]-num[i-1]!=0)number.push_back(num[i]);
        int ans[10001]={};
        for(int i=0;i<number.size();i++){
            for(int j=0,k;j<number.size();j++){
                k=number[i]-number[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 <iostream>
#include <set>
#include <cstring>
using namespace std;

int main(void){
	int n;

	while(cin>>n && n){
		set<int> first;
		for(int i=1;i<n;i++){
			first.insert(i*i%n);
		}

		int max = (n-1) / 2;
		int count[max+1];
		memset(count,0,sizeof(count));
		for(set<int>::iterator i = first.begin(); i != first.end(); i++){
			for(set<int>::iterator j = i; j != first.end(); j++){
				if(*i == *j) continue;

				int diff = *i - *j;
				if(diff <= 0) diff += n;
				if(diff > max) diff = n - diff;
				count[diff]++;
			}
		}

		for(int i=1;i<=max;i++){
			cout<<count[i]<<endl;
		}
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

static const double eps = 10e-9;

int main(){
	int n;

	while(~scanf("%d",&n)){
		if(n==0) break;

		vector<int> input;
		for(int i=1;i<=n-1;i++){
			input.push_back((i*i)%n);
		}

		int* table = new int[(n-1)/2+1]();

		sort(input.begin(),input.end());

		vector<int>::iterator end_it = unique(input.begin(),input.end());
		input.erase(end_it,input.end());

		for(int i=0;i<input.size();i++){
			for(int j=0;j<input.size();j++){
				if(i==j) continue;
				int calc = input[i]-input[j] ;
				if(calc < 0) calc+=n;
				if(calc > (n-1)/2) calc = n - calc;

				table[calc]++;
			}
		}

		for(int i=1;i<(n-1)/2+1;i++){
			printf("%d\n",table[i]);
		}

		delete[] table;
	}
}

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

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<int> sqmod;
    for(int i = 1; i < N; ++i)
      sqmod.push_back((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 <cstring>
#include <iostream>
using namespace std;
int n, 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), n) {
		if(p[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);
	}
}