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>
using namespace std;
int n;
bool is_nijo[100001];
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++) { //n=3??

	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 <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
 
    while (scanf("%d", &n), n) {
	int MAX = (n-1) / 2;
	int cnt[MAX];
	fill(cnt, cnt+MAX, 0);
 
	set<int> s;
	for (int i = 1; i < n; i++) {
	    int num = i * i % n;
	    if (!s.count(num)) {
		s.insert(num);
	    }
	}
 
	set<int>::iterator it;
	vector<int> v;
	for (it = s.begin(); it != s.end(); it++) {
	    v.push_back(*it);
	}
	int len = (int)v.size();
	for (int i = 0; i < len; i++) {
	    for (int j = 0; j < len; j++) {
		if(i == j) continue;
		int diff = v[i] - v[j];
 
		if (diff < 0) {
		    diff += n;
		}
		if (diff > MAX) {
		    diff -= n;
		}
 
		cnt[diff-1]++;
	    }
	}
	for (int i = 0; i < MAX; i++) {
	    printf("%d\n", cnt[i]*2);
	}
    }
    return 0;
}

C++: #include <cstdio>           // printf(), scanf()
#include <set>

using namespace std;

const int MAX_N = 10000;
const int MAX_R = 5000;

void
solve(int n)
{
	int bins[MAX_N / 2];
	set<int> remains;
	int re[MAX_R];

	int ix = 0;
	for (int i = 1; i < n; ++i)
	{
		int r = (i * i) % n;

		if (remains.find(r) == remains.end())
		{
			remains.insert(r);
			re[ix++] = r;
		}
	}

	int m = (n - 1) / 2;
	for (int i = 1; i <= m; ++i)
		bins[i] = 0;

	for (int i = 0; i < ix; ++i)
	{
		for (int j = i + 1; j < ix; ++j)
		{
			if (i != j)
			{
				int d = re[i] - re[j];
				if (d < 0)
					d += n;

				if (d > m)
					d = n - d;

				bins[d]++;
			}
		}
	}

	for (int i = 1; i <= m; ++i)
		printf("%d\n", 2 * bins[i]);
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		solve(n);
	}

	return 0;
}

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<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main()
{
  int ans[100000000],n; 
  while(cin >> n,n)
    {
      vector<int> vec;
      rep(i,(int)((n-1)/2)+1)ans[i] = 0;
      REP(i,1,n)vec.push_back((i*i)%n);
      sort(vec.begin(),vec.end()); 
      vec.erase(unique(vec.begin(),vec.end()),vec.end());
      rep(i,vec.size())
	{
	  rep(j,vec.size())
	    {
	      int diff = vec[i] - vec[j];
	      if(diff < 0)diff += n;
	      if(diff > (n-1)/2)diff = n - diff;
	      if(1 <= diff && diff <= (n-1)/2)ans[diff]++;
	    }
	}
      REP(i,1,(int)((n-1)/2)+1)cout << ans[i] << endl;
    }
  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;

int n;
vector<int> v1,v2;

int main(){
	while (cin >> n&&n){
		FOR(i, 1, n){
			int k = i*i % n;
			if (find(ALL(v1), k) == v1.end()){
				v1.push_back(k);
			}
		}
		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);
				}
			}
		}
		sort(ALL(v2));
		FOR(i, 1, (n - 1) / 2 + 1){
			cout << upper_bound(ALL(v2), i) - lower_bound(ALL(v2), i) << endl;
		}
		v1.clear();
		v2.clear();
	}
}

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

using namespace std;

int main(){
	
	int n, a[20000];
	
	bool exist[20000];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		if(n < 6){
			while(true){
			}
		}
		for(int i = 1; i < n; i++){
			exist[i] = false;
			a[i] = 0;
		}
		for(int i = 1; i < n; i++){
			exist[(i * i) % n] = true;
		}
		
		int dummy;
		
		for(int i = 1; i < n; i++){
			for(int j = 1; j < n; j++){
				if(i == j){
					continue;
				}
				if(exist[i] && exist[j]){
					dummy = i - j;
					if(dummy < 0){
						dummy += n;
					}
					if(dummy > (n - 1) / 2){
						dummy = n - dummy;
					}
					a[dummy]++;
				}
			}
		}
		
		for(int i = 1; i <= n / 2; i++){
			printf("%d\n", a[i]);
		}
	}
	
	return 0;
}

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();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;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)


void solve(int n) {
  vector<int> v;
  for(int s = 1; s <= n-1; s++) {
    v.push_back(s*s%n);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  int cnt[10001];
  fill(cnt, cnt+(n-1)/2+1, 0);
  rep(b, v.size()) {
    rep(a, v.size()) {
      if(a == b) continue;
      int k = v[b] - v[a];
      if(k < 0) k += n;
      if(k > (n-1)/2) k = n - k;
      cnt[k]++;
    }
  }
  for(int i = 1; i <= (n-1)/2; i++) cout << cnt[i] << endl;
}

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