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 <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++: using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var n2 = (n - 1) / 2;
            var w1 = new List<int>();
            for (int i = 1; i < n; i++) w1.Add(i * i  % n);
            var w2 = w1.Distinct().ToArray();
            var ret = new int[n2];
            for (int i = 0; i < w2.Length; i++)
                for (int j = 0; j < w2.Length; j++)
                    if (i != j)
                    {
                        var z = w2[i] - w2[j];
                        if (z < 0) z += n;
                        if (z > n2) z = n - z;
                        ret[z-1]++; 
                    }
            foreach (var x in ret)
                Console.WriteLine(x);
        }
    }
}

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.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 <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
	int n;
	while (cin >> n, n) {
		vector<int> rems;
		for (int i = 1; i < n; i++) {
			rems.push_back((i * i) % n);
		}
		sort(rems.begin(), rems.end());
		rems.erase(unique(rems.begin(), rems.end()), rems.end());
		vector<int> results((n - 1) / 2 + 1, 0);
		for (unsigned i = 0; i < rems.size(); i++) {
			for (unsigned j = 0; j < rems.size(); j++) {
				if (i == j) continue;
				int x = rems[i] - rems[j];
				if (x < 0) x += n;
				if ((n - 1) / 2 < x) x = n - x;
				results[x]++;
			}
		}
		for (unsigned i = 1; i < results.size(); i++) {
			cout << results[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=0;i<n/2;)printf("%d\n",v[++i]);}}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
#include<set>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()
#define foreach(p,r) for(p::iterator it=r.begin();it!=r.end();++it)

const int MAXN = 10000;
vector<int> nums(MAXN);
vector<int> ans(MAXN);
int main()
{
    int n;
    while(cin >> n && n)
    {
        int half = (n-1)/2;
        set<int> sq;
        fill(all(ans),0);

        REP(n - 1) sq.insert(((i + 1) * (i + 1)) % n);
        int l = 0;
        foreach(set<int>,sq){ nums[l] = *it ; l++;}

        //REP(l-1)for(int j = i+1;j<l;j++)
        REP(l)rep(j,l)
        {
            if(i==j) continue;
            int res = nums[j] - nums[i];
            if(res < 0) res += n;
            if(res > half) res = n - res;
            ans[res]++;
            //cout <<"add" <<  res <<endl;
        }
        REP(half) cout << ans[i + 1] << 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(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;)printf("%d\n",v[++i]);}}

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

bool exists(vector<int> v, int n) {
    for (int i = 0; i < v.size(); i++) {
        if (v[i] == n) return true;
    }
    return false;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;
        int count[(n - 1) / 2 + 1];
        vector<int> mod;
        for (int i = 0; i < (n - 1) / 2 + 1; i++) {
            count[i] = 0;
        }
        for (int i = 1; i < n; i++) {
            int res = (i * i) % n;
            if (!exists(mod, res)) {
                mod.push_back(res);
            }
        }
        for (int i = 0; i < mod.size(); i++) {
            for (int j = 0; j < mod.size(); j++) {
                if (i == j) continue;
                int res = mod[i] - mod[j];
                if (res < 0) res += n;
                if (res > (n - 1) / 2) res = n - res;
                count[res]++;
            }
        }
        for (int i = 1; i < (n - 1) / 2 + 1; i++) {
            cout << count[i] << endl;
        }
    }
}

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 <set>
#include <map>
#include <cstdio>
using namespace std;
int main(){
	int i,n;
	for(;scanf("%d",&n),n;){
		set<int>s;
		map<int,int>v;
		for(i=1;i<n;i++)s.insert(i*i%n);
		set<int>::iterator is,iS;
		for(is=s.begin();is!=s.end();is++)
			for(iS=is,iS++;iS!=s.end();iS++){
				i=*iS-*is;
				if(i>(n-1)/2)i=n-i;
				v[i]++;
			}
		for(i=1;i<=(n-1)/2;i++)printf("%d\n",v[i]*2);
	}
}