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 <set>
using namespace std;

int main()
{
	int n;

	while( cin >> n && n ){
		set< int > list;
		int size = ( n - 1 ) / 2;
		int* counts = new int[ size + 1 ]();
		for( int i = 1; i < n; ++i ){
			list.insert( i * i % n );
		}
		set< int >::iterator itr1 = list.begin();
		set< int >::iterator itr2 = list.begin();
		while( itr1 != list.end() ){
			while( itr2 != list.end() ){
				if( itr1 == itr2 ){
					++itr2;
					continue;
				}
				int a = *itr1;
				int b = *itr2;
				int diff = a - b;
				if( diff < 0 ){
					diff += n;
				}
				if( diff > size ){
					diff = n - diff;
				}
				++counts[ diff ];

				++itr2;
			}
			++itr1;
			itr2 = list.begin();
		}

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

		delete[] counts;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

set<int> app;

main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		
		app.clear();
		
		for(int i=1;i<n;i++){
			app.insert(i*i%n);
		}
		vector<int> vapp((n-1)/2);
		for(set<int>::iterator sp=app.begin();sp!=app.end();sp++){
			for(set<int>::iterator tsp=app.begin();tsp!=app.end();tsp++){
				if(sp==tsp)continue;
				int diff=*tsp-*sp;
				if(diff<0)diff+=n;
				if(diff>(n-1)/2)diff=n-diff;
				vapp[diff-1]++;
			}
		}
		for(int i=0;i<vapp.size();i++){
			cout<<vapp[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!=t.end();s++)for(auto 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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    set<int> c;
    FOR(i,1,n){
      int mod = (i*i)%n; 
      c.insert(mod);
    }
    int count[5001]={0};
    vector<int> d;
    set<int>::iterator it = c.begin();
    for(;it!=c.end(); it++){
      d.push_back((*it));
    }
    FOR(i,0,d.size()){
      FOR(j,i+1,d.size()){
        count[ min( abs(d[i]-d[j]), n - abs(d[i]-d[j])) ]++;
      }
    }
    FOR(i,1,(n-1)/2+1){
      cout<<2*count[i]<<endl;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <map>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  while(cin >> n,n){
    map<ll,ll>mp,ans;
    for(int i = 1 ; i*2 < n ; i++ ){
      mp[(i*i)%n] = 1;
    }

    map<ll,ll>::iterator a =  mp.begin(),b;
    for(; a != mp.end() ; a++ ){
      for(b = a; b != mp.end() ; b++ ){
	if(*b == *a)continue;
	if(((*b).first - (*a).first) > (n-1)/2 ){
	  ans[n - (*b).first + (*a).first]+=2;
	} else {
	  ans[(*b).first - (*a).first]+=2;
	}
      }
    }
    map<ll,ll>::iterator it =  ans.begin();
        for(; it != ans.end() ; it++)cout << (*it).second << endl;
  }
  return 0;
}

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

int main()
{
  int n;
  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);
	    }
	}
      int ans[(n-1)/2+2];
      memset(ans,0,sizeof(ans));
      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[tmp]++;

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

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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int data[20000];

int f(int tmp,int n){
    if(data[10000+tmp]!=-1)return data[10000+tmp];
    int pre = tmp;
    while(1){
        bool f=true;
        if(tmp<0)tmp+=n,f=false;
        if(tmp>(n-1)/2)tmp = n-tmp,f=false;
        if(f)break;
    }
    data[10000+pre] = tmp;
    return tmp;
}

int main(){
    int n;
    while(cin>>n&&n){
        rep(i,20000)data[i] = -1;
        set<int> a;
        for(int i=1;i<n;i++){
            a.insert( (i*i)%n );
        }
        
        vector<int> vec;
        for(int x : a) vec.pb(x);
        map<int,int> b;

        rep(i,vec.size()){
            rep(j,vec.size()){
                if(i==j)continue;
                int tmp = vec[i]-vec[j];
                tmp = f(tmp,n);
                b[tmp]++;
            }
        }
        for(pii x : b){
            printf("%d\n",x.second);
        }
    }
}