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

int main()
{
	int n;
	vector<int> num(10002);
	set<int> a;
	set<int>::iterator it, itr, ite;
	int i, t;

	while (cin>>n, n) {
		a.clear();
		for (i = 0; i < n; i++) num[i] = 0;
 		for (i = 1; i < n; i++) a.insert((i*i)%n);
		ite = a.end();
		ite--;
		for (it = a.begin(); it != ite; it++) {
			itr = it;
			for (itr++; itr != a.end(); itr++) {
				t = *it - *itr;
				if (t < 0) t += n;
				if ((n-1)/2 < t) t = n-t;
				num[t] += 2;
			}
		}
		for (i = 1; i <= (n-1)/2; i++)
			cout<<num[i]<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int number[10001];
    for(int i=1;i<10000;i++)number[i]=i*i;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(number[i]%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[5000]={};
        for(int i=0;i<num.size()-1;i++){
            for(int j=i+1,k;j<num.size();j++){
                k=num[i]-num[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]*2<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int number[9999];
    for(int i=1;i<9999;i++)number[i]=i*i;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(number[i]%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[5000]={};
        for(int i=0;i<num.size();i++){
            for(int j=0,k;j<num.size();j++){
                k=num[i]-num[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++: /*
 * 0142.cpp
 *
 *  Created on: 2011/07/27
 *      Author: isa
 */

#include <iostream>
#include <set>
#include <map>
#include <cstring>

using namespace std;

int main(void){
	int n;

	while(cin >> n && n){
		set<int> s;
		int times[((n-1)/2)+1];

		memset(times,0,sizeof(times));
		for(int i=1;i<n;i++){
			s.insert((i*i)%n);
			//cout << i*i%n << endl;
		}

		set<int>::iterator it,jt;

		for(it = s.begin(); it != s.end(); ++it){
			for(jt = s.begin(); jt != s.end(); ++jt){
				int tmp;
				if(it == jt) continue;
				tmp = *it - *jt;
				if(tmp < 0) tmp+=n;
				if(tmp > (n-1)/2) tmp = n - tmp;
				times[tmp]++;
			}
		}
		for(int i=1;i<=(n-1)/2;i++){
			cout << times[i] << endl;
		}

	}
}

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

int main() {
    int n;
    while(cin>>n, n) {
        vector<int> vi;
        for(int i=1; i<n; ++i)
            vi.push_back(i*i%n);

        sort(vi.begin(), vi.end());
        vector<int>::iterator uni = unique(vi.begin(), vi.end());
        vi.erase(uni, vi.end());

        int cnt[(n-1)/2+1];
        memset(cnt, 0, sizeof(cnt));

        for(int i=0; i<vi.size(); ++i) {
            for(int j=i+1; j<vi.size(); ++j) {
                int ci = vi[i] - vi[j];
                if(ci < 0) ci += n;
                if(ci > (n-1)/2) ci = n - ci;
                cnt[ci]++;
            }
        }

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

C++: #include<iostream>
#include<set>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		set<int>M;
		for(int i=1;i<n;i++)M.insert(i*i%n);
		int cnt[5555]={};
		for(int a:M)
		{
			for(int b:M)
			{
				if(a==b)continue;
				int d=a-b;
				if(d<0)d+=n;
				if(d>n/2)d=n-d;
				cnt[d]++;
			}
		}
		for(int i=1;i<=n/2;i++)cout<<cnt[i]<<endl;
	}
}

C++: #include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int nums[16384], ans[8192];
	int i, j, n, size, half, p;
	
	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 = unique(nums, nums + size) - nums;

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

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

//MLE
int n;
vector<int> v1, v2;

int main(){
	while (cin >> n&&n){
		ll co[1000] = {};
		FOR(i, 1, n){
			int k = i*i % n;
			v1.push_back(k);
		}
		sort(ALL(v1));
		v1.erase(unique(ALL(v1)), v1.end());
		//REP(i, v1.size())cout << v1[i] << " ";
		REP(i, v1.size()){
			REP(j, v1.size()){
				if (i != j){
					int k = v1[i] - v1[j];
					if (k < 0)k += n;
					if (k >(n - 1) / 2)k = n - k;
					v2.push_back(k);
				}
			}
		}
		REP(i, v2.size()){
			co[v2[i]]++;
		}
		FOR(i, 1, (n - 1) / 2 + 1){
			cout << co[i] << endl;
		}
		v1.clear();
		v2.clear();
	}
}

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);
	std::set<int>::iterator s,S;
	for(s=t.begin();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 <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int ok(int n){
	if(n < 2)return 0;
	for(int i = 2 ; i*i <= n ; i++){
		if(n % i == 0) return 0;
	}
	return 1;
}
int main(){
	int n;
	while(cin >> n,n){
		set<int> r;
		for(int i = 1 ; i < n ; i++) r.insert((i*i)%n);
		vector<int> wow;
		for(set<int>::iterator it = r.begin() ; it != r.end() ; ++it)
			wow.push_back(*it);
		map<int,int> mp;
		for(int i = 0 ; i < wow.size() ; i++){
			for(int j = 0 ; j < wow.size() ; j++){
				if( i == j) continue;
				int g = wow[i] - wow[j];
				if(g < 0) g += n;
				if(g > (n-1)/2) g = n - g;
				mp[g]++;
			}
		}
		for(int i = 1 ; i <= (n-1)/2 ; i++)
			cout << mp[i] << endl;
	}
}

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

int main(){
	int n, arr[5000];
	std::vector<int> v;
	while(std::cin >> n, n){
		std::fill(arr, arr+5000, 0);
		v.clear();

		for(int i=1;i<=(n-1)/2;i++){
			if(std::find(v.begin(), v.end(), i*i%n) == v.end()){//まだない
				v.push_back(i*i%n);
			}
		}

		for(int i=0;i<v.size()-1;i++){
			for(int j=i+1;j<v.size();j++){
				int value = v[i] - v[j];
				if(value < 0){
					value += n;
				}
				if(value > (n-1)/2){
					value = n - value;
				}
				arr[value]++;
			}
		}

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