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;
const int INF = (1<<20);

int data[MAX],n;


void solve(){
  vector<int> V;
  fill(data,data+MAX,0);
  for(int i = 1; i < n; i++){
    V.push_back((i*i)%n);
  }
  V.push_back(-1);
  V.push_back(INF);
  sort(V.begin(),V.end());
  vector<int> VV;
  int now = -1;
  while(1){
    now = *upper_bound(V.begin(),V.end(),now);
    if(now == INF) break;
    VV.push_back(now);
  }
  for(int i = 0; i < VV.size(); i++)
    for(int j = 0; j < VV.size(); j++){
      //if(VV[i]!=VV[j]) {
      int num = VV[i]-VV[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<iostream>
#include<map>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
  int ans[10001][10000/2];
int main()
{
  int n;

  memset(ans,0,sizeof(ans));
  map<int,bool>closed;
  for(;cin>>n,n;)
    {

      map<int,bool>hash;
      vector<int> data;
      for(int i=1;i<n;i++)
	{
	  if(hash.count(i*i%n)==0)
	    {
	      hash[i*i%n]=true;
	      data.push_back(i*i%n);
	    }
	}
      if(closed.count(n)==0)
	{
	  for(int i=0;i<data.size()-1;i++)
	    for(int j=i+1;j<data.size();j++)
	      {
		int tmp=data[i]-data[j];
		if(tmp<0)
		  tmp+=n;
		if(tmp>(n-1)/2)
		  tmp=n-tmp;
		ans[n][tmp]++;

	    tmp=data[j]-data[i];
	    if(tmp<0)
	      tmp+=n;
	    if(tmp>(n-1)/2)
	      tmp=n-tmp;
	    ans[n][tmp]++;
	  }
	}
      for(int i=1;i<=(n-1)/2;i++)
	cout<<ans[n][i]<<endl;
    }
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n;
  vector<int> c;
  list<int> l;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    l.clear();
    for(i=1;i<n;i++){
      l.remove(i*i%n);
      l.push_back(i*i%n);
    }
    c.assign(n/2+1,0);
    list<int>::iterator it=l.begin();
    for(;it!=l.end();it++){
      list<int>::iterator jt=l.begin();
      for(;jt!=l.end();jt++){
	if(*it!=*jt){
	  int a;
	  a=*it-*jt;
	  if(a<0)
	    a+=n;
	  if(a>n/2)
	    a=n-a;
	  c[a]++;
	}
      }
    }
    for(i=1;i<n/2+1;i++)
      cout<<c[i]<<endl;
  }
  return 0;
}

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

using namespace std;

int num(int x, int& n){
  if(x < 0) x += n;
  if(x > (n-1)/2) return n-x;
  return x;
}

int main(){
  int n;
  while(1){
    cin >> n;
    if(!n) break;
    set<int> x;
    for(int i=1; i<n; ++i) x.insert((i*i)%n);
    vector<int> ans((n-1)/2+1, 0);
    for(set<int>::iterator it=x.begin(); it!=x.end(); ++it){
      for(set<int>::iterator jt=it; jt!=x.end(); ++jt){
	if(jt == it) continue;
	++ans[num(*it-*jt, n)];
	++ans[num(*jt-*it, n)];
      }
    }
    for(int i=1; i<ans.size(); ++i) cout << ans[i] << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        set<int>S;
        for(int i=1;i<n;i++)S.insert((i*i)%n);
        int cnt[10000]={0};
        vector<int>V;
        for(set<int>::iterator it=S.begin();it!=S.end();it++)V.push_back(*it);
        for(int i=0;i<V.size();i++){
            for(int j=0;j<V.size();j++){
                if(i==j)continue;
                int a=V[i],b=V[j];
                int val=a-b;
                if(val<0)val+=n;
                if(val>(n-1)/2)val=n-val;
                cnt[val]++;
            }
        }
        for(int i=1;i<=(n-1)/2;i++)printf("%d\n",cnt[i]);
    }
    return 0;
}

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

int n;
int main() {
    while (cin >> n, n != 0) {
        set<int> mod;
        for (int i = 1; i < n; i++) 
            mod.insert( (i*i) % n );

        int count[(n-1)/2+1];
        memset(count, 0, sizeof(count));
        for (set<int>::iterator si = mod.begin();
                si != mod.end(); si++) {
            for (set<int>::iterator sj = mod.begin();
                    sj != mod.end(); sj++) {
                if (*si == *sj) continue;
                int dif = *si - *sj;
                if (dif < 0) dif += n;
                if (dif > (n-1)/2) dif = n - dif;
                count[dif]++;
            }
        }

        for (int i = 1; i <= (n-1)/2; i++) 
            cout << count[i] << endl;
    }   
    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[10000]={};
        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>

using namespace std;


int main(void)
{
	 int n;
	set<int> target;
	multiset<int> data;

	while( cin >> n && n != 0 ){
		target.clear();
		data.clear();
		for( int i = 1;i < n;i++ ){
			target.insert( i * i % n );
		}

		for( set<int>::iterator it = target.begin();it != target.end();it++ ){
			set<int>::iterator it2 = target.begin();
			for(;it2 != target.end();it2++ ){
				int answer = *it - *it2;
				while( 1 ){
					if( answer < 0 ){ answer += n; continue; }
					else if( answer > ( n - 1 ) / 2 ){ answer = n - answer; continue; }
					data.insert( answer );
					break;
				}
			}
		}

		for(  int i = 1;i <= ( n - 1 ) / 2;i++ ){
			cout << data.count( i ) << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        set<int> si;
        for(int i=1; i<n; ++i)
            si.insert(i*i%n);

        vector<int> ret((n-1)/2+1, 0);
        set<int>::iterator it1, it2;
        for(it1=si.begin(); it1!=si.end(); ++it1){
            for(it2=it1, ++it2; it2!=si.end(); ++it2){
                int a = (*it1) - (*it2);
                if(a < 0)
                    a += n;
                if(a > (n-1)/2)
                    a = n - a;
                ret[a] += 2;
            }
        }

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