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 <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	vi nums;
	nums.reserve(10000);
	
	while(scanf("%d", &n), n){
		reep(i, 1, n)
			nums.push_back((i*i)%n);
		int half = (n-1) / 2;
		
		sort(nums.begin(), nums.end());
		int size = distance(nums.begin(), unique(nums.begin(), nums.end()));
		
		vi ans(half+1, 0);
		rep(i, size){
			rep(j, i+1){
				int p = abs(nums[i]-nums[j]);
				if(p>half) p = n - p;
				++ans[p];
			}
		}
		reep(i, 1, half+1)
			printf("%d\n", ans[i]*2);
	}
	
	return 0;
}

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

bool f[10000];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		memset(f, false, sizeof(f));
		for (int i = 1; i < n; i++){
			f[i * i % n] = true;
		}
		vector<int> v;
		for (int i = 0; i < n; i++){
			if (f[i]) v.push_back(i);
		}
		int cnt[10000] = {};
		for (int i = 0; i < v.size(); i++){
			for (int j = 0; j < v.size(); j++){
				if (i == j) continue;
				int x = v[i] - v[j];
				if (x < 0) x += n;
				if (x > (n - 1) / 2) x = n - x;
				cnt[x]++;
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++){
			printf("%d\n", cnt[i]);
		}
	}
	return 0;
}

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

using namespace std;

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

int main() {
  for (;;) {
    cin >> n;
    if (!n) return 0;
    memset(results, 0, sizeof results);
    remss.clear();
    memset(remsv, 0, sizeof remsv);
    for (int i = 1; i < n; i++)
      remss.insert(i * i % n);
    copy(remss.begin(), remss.end(), remsv);
    for (int i = 0; i < remss.size()-1; i++)
      for (int j = i+1; j < remss.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 <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;
  }
  /*int p = prime2[(int)prime2.size()-1];
  for(int i=1;i<prime2.size();i++){
    if(prime2[i] > n){
      p = prime2[i];
    }
  }
  fill(data, data+size, 0);
  int size2 = (p-1)/2;
  for(int i=0;i<size2;i++){
    data[i] = size2-1;
  }
  used.clear();
  for(int i=p;i<n;i++){
    int tmp = (i*i)%n;
    if(tmp > size2) used.insert(tmp);
  }
  set<int>::iterator ite = used.begin();
  for(;ite!=used.end();ite++){
    for(int i=0;i<size2;i++){
      int a = *ite;
      int b = i+1;
      int c = a-b;
      if(c < 0) c += 11;
      if(c > size) c = 11 - c;
      ++data[c];
      c = b-a;
      if(c < 0) c += 11;
      if(c > size) c = 11 - c;
      ++data[c];
    }
    }*/
  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++: #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 <set>
using namespace std;

int main() {
  int n, t;
  int d[5000];
  set<int> s;

  while (1) {
    cin >> n;
    if (!n) break;
    s.clear();
    for (int i=1; i<n; i++) {
      s.insert((i*i)%n);
    }
    for (int i=1; i<=(n-1)/2; i++) {
      d[i] = 0;
    }
    for (set<int>::iterator it1=s.begin(); it1!=s.end(); it1++) {
      for (set<int>::iterator it2=s.begin(); it2!=s.end(); it2++) {
        if (it1 == it2) continue;
        t = *it1 - *it2;
        if (t < 0) t += n;
        if (t > (n-1)/2) t = n - t;
        ++d[t];
      }
    }
    for (int i=1; i<=(n-1)/2; i++) {
      cout << d[i] << endl;
    }
  }
  return 0;
}

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

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi nums;
		reep(i, 1, n)
			nums.push_back((i*i)%n);
		
		sort(nums.begin(), nums.end());
		nums.erase(unique(nums.begin(), nums.end()), nums.end());
		
		vi ans((n+1)/2, 0);
		rep(i, nums.size()){
			rep(j, i+1){
				int p = abs(nums[i]-nums[j]);
				if(p>(n-1)/2) p = n - p;
				++ans[p];
			}
		}
		reep(i, 1, (n+1)/2)
			printf("%d\n", ans[i]*2);
	}
	
	return 0;
}