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<algorithm>
#include<vector>

using namespace std;

const int MAX = 10000;
int data[MAX],n;


void solve(){
  vector<int> V;
  fill(data,data+MAX,0);
  for(int i = 1; i < n; i++){
    sort(V.begin(),V.end());
    if(!(binary_search(V.begin(),V.end(),(i*i)%n)))
      V.push_back((i*i)%n);
  }

  for(int i = 0; i < V.size(); i++)
    for(int j = 0; j < V.size(); j++)
      if(i!=j) {
	int num = V[i]-V[j];
	if(num < 0) num += n;
	if(num > (n-1)/2) num = n-num;
	data[num]++;
      }
}

void print(){
  for(int i = 1; i <= (n-1)/2; i++)
    cout << data[i] << endl;
}


int main(){
  while(cin >> n && n){
    solve();
    print();
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int p[10000],c[9999],n;
  r(i,10000)p[i]=i*i;
  while(cin>>n,n){
    memset(c,0,sizeof(c));
    vector<int>v;
    r(i,n-1)v.push_back(p[i+1]%n);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    r(i,v.size())r(j,i)if(i!=j){
      int x=v[i]-v[j];
      if(x<0)x+=n;
      else if(x>(n-1)/2)x=n-x;
      c[x]+=2;
    }
    r(i,v.size())cout<<c[i+1]<<endl;
  }
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		bool isAppeared[10001];
		int data[10001];
		fill(isAppeared,isAppeared+10001,false);
		fill(data,data+10001,0);
		//memset(isAppeared,0,sizeof(isAppeared));
		//memset(data,0,sizeof(data));
		for(int i = 1; i < n; i++){
			int r=(i*i)%n;
			isAppeared[r]=true;
		}
		for(int i = 0; i < 10001; i++){
			for(int j = 0; j < 10001; j++){
				if(isAppeared[i]&&isAppeared[j]){
					int ret=i-j;
					if(ret<0)
						ret+=n;
					if(((n-1)/2)<ret){
						ret=n-ret;
					}
					data[ret]++;
				}
			}
		}
		for(int i = 1; i <= ((n-1)/2); i++){
			if(data[i]!=0)
				cout<<data[i]<<endl;
		}
	}

	return 0;
}

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>
using namespace std;
int n,x,y;
int isP[1000000];
int t[10000],u[10000],ans[10000];
void Prime(){
  for(int i=0;i<1000001;i++)isP[i]=1;
  isP[0]=isP[1]=0;
  for(int i=2;i*i<1000001;i++){
    if(isP[i])for(int j=i*i;j<1000001;j++)isP[j]=0;
  }
}
void init(){
  for(int i=0;i<10000;i++)ans[i]=t[i]=0;
}
int main(){
  Prime();
  while(cin>>n&&n){
    init();
    for(int i=0;i<n-1;i++){
      t[((n-i-1)*(n-i-1))%n]=1;
    }
    x=0;
    for(int i=0;i<10001;i++){
      if(t[i])u[x++]=i;
    }
    for(int i=0;i<x;i++){
      for(int j=0;j<x;j++){
	if(i==j)continue;
	y=u[i]-u[j];
	if(y<0)y+=n;
	if(y>((n-1)/2))y=n-y;
	ans[y]++;
      }
    }
    for(int i=1;i<=(n-1)/2;i++){
      cout<<ans[i]<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
using namespace std;
int t[1000000];
int u[1000000],us;
int v[1000000];
int n,a,size;
int main(){
  while(cin>>n&&n){
    size=(n-1)/2;
    for(int i=0;i<1000000;i++)t[i]=u[i]=v[i]=0;
    us=0;

    for(int i=1;i<n;i++){
      a=i*i%n;
      t[a]++;
      if(t[a]==1)u[us++]=a;
    }

    for(int i=0;i<us;i++){
      for(int j=0;j<us;j++){
	if(i==j)continue;
	a=u[i]-u[j];
	if(a<0)a+=n;
	if(a>size)a=n-a;
	v[a]++;
      }
    }
    for(int i=1;i<=size;i++){
      cout<<v[i]<<endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
  
  int N;
  
  while(cin >> N && N) {
    map<int, int> mp;
    set<int> st;
    for(int i=1; i<N; i++) {
      st.insert(i*i % N);
    }
    
    vector<int> vec;
    for(set<int>::iterator it = st.begin(); it!=st.end(); it++) {
      vec.push_back(*it);
    }
    
    int const M = st.size();
    
    for(int i=0; i<M; i++) {
      for(int j=0; j<M; j++) {
	if(vec[i] == vec[j]) continue;
	
	int diff = vec[i]-vec[j];
	if(diff < 0) diff += N;
	if((N-1)/2 < diff) {
	  diff = N - diff;
	}
	mp[diff] ++;
      }
    }
    
    for(int i=1; i<=(N-1)/2; i++) {
      cout << mp[i] << endl;
    }
  }
  
  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 nums[10000];
	int i, j, n, size, half;
	while(scanf("%d", &n), n){
		size = 0;
		half = (n-1) / 2;
		for(i=1; i<n; ++i)
			nums[size++] = (i*i) % n;

		sort(nums, nums + size);
		size = distance(nums, unique(nums, nums + size));

		vi ans(half+1, 0);
		for(i=0; i<size; ++i){
			for(j=0; j<i; ++j){
				int p = abs(nums[i]-nums[j]);
				if(p>half) p = n - p;
				++ans[p];
			}
		}
		for(i=1; i<=half; ++i)
			printf("%d\n", ans[i]*2);
	}

	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]++;
	}

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

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

vector<int> p;
int use[10000];
int ans,n,ansp[10000];
void dfs(int x){
  for(int i=0;i<(int)p.size();i++){
       if(p[x]!=p[i]) ans=p[x]-p[i];
    else continue;
    if(ans<0) ans+=n;
    if(ans>(n-1)/2) ans=n-ans;
    ansp[ans]++;
  }
  if(x+1<(int)p.size())dfs(x+1);
  }

int main(){
  while(1){
  cin>>n;
  if(n==0) break;
  int t;
  for(int i=0;i<10000;i++) use[i]=0,ansp[i]=0;
    for(int i=1;i<n;i++)t=(i*i)%n,use[t]=1;
    for(int i=0;i<n;i++) if(use[i]==1) p.push_back(i);
    dfs(0);
    for(int i=1;i<=(n-1)/2;i++) cout<<ansp[i]<<endl;
    p.clear();
  }
  return 0;
}