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

int main () {
  int n;
  int mp[5000];

  while(cin >> n && n) {
	for(int i=1; i<=(n-1)/2; i++) mp[i] = 0;
	for(int a=1; a<n-1; a++) {
	  for(int b=a+1; b<n; b++) {
		int d = (a*a)%n - (b*b)%n;
		if(d < 0) d+=n;
		if(d>(n-1)/2) d=n-d;
		mp[d] ++;
	  }
	}
	for(int i=1; i<=(n-1)/2; i++) {
	  cout << mp[i] << endl;
	}
  }
  
  return 0;
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int main()
{
  int n;
  while (n = in()){
    vector<int> v;
    vector<int> counter((n - 1) / 2, 0);
    lep(i, n - 1) v.push_back(i * i % n);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    rep(i, v.size()){
      rep(j, v.size()){
        if (i == j) continue;
        int x = v[i] - v[j];
        if (x < 0) x += n;
        if (x > (n - 1) / 2) x = n - x;
        counter[x - 1]++;
      }
    }
    show(counter);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
	int n;
	while (cin >> n, n) {
		set<int> st;
		rep(i, 1, n) {
			int tmp = i * i % n;
			if (!st.count(tmp)) {
				st.insert(tmp);
			}
		}
		vi d(n / 2 + 1, 0);
		for (auto i = st.begin(); i != st.end(); i++) {
			for (auto j = st.begin(); j != st.end(); j++) {
				int tmp = abs(*i - *j);
				if (tmp > n / 2) {
					tmp = n - tmp;
				}
				d[tmp]++;
			}
		}
		rep(i, 1, n / 2 + 1) {
			cout << d[i] << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 10010;

int main(void){
    int square[MAX];
    for (int i=1; i < MAX+1; i++) square[i-1] = i*i;
    
    while (true){
        int n,size;
        int raw_mod[MAX],mod[MAX],hist[MAX] = {};
        
        cin >> n;
        if (n == 0) break;
        int m = (n-1)/2;
        
        for(int i = 0; i < n-1; i++) raw_mod[i] = square[i]%n;
        sort(raw_mod,raw_mod+n-1);
        
        mod[0] = raw_mod[0];
        for(int i = 1, j = 1; i < n-1; i++){
            if (mod[j-1] != raw_mod[i]){
                mod[j] = raw_mod[i];
                j++;
            }
            size = j;
        }

        for (int i = 0; i < size-1; i++)
            for (int j = i+1; j < size; j++){
                
                int tmp1 = mod[i]-mod[j];
                if (tmp1 < 0) tmp1 += n;
                if (tmp1 > m) tmp1 = n-tmp1;
                
                int tmp2 = mod[j]-mod[i];
                if (tmp2 < 0) tmp2 += n;
                if (tmp2 > m) tmp2 = n-tmp2;
                
                hist[tmp1-1] += 1;
                hist[tmp2-1] += 1;
            }

        for(int i = 0; i < m; i++)
            cout << hist[i] << endl;
    }
    return 0;    
}

C++: //Name: Nature of Prime Numbers
//Level: 1
//Category: やるだけ
//Note: 問題文が読みにくい

/**
 * 問題文がかなり分かりにくいが、要するに
 * ・a_i = i^2 mod n (1 ≦ i < n)
 * ・S = unique set of a_i
 * ・d_j = (a - b) mod n (a, b ∈ S, a≠b)
 * ・e_j = max(0, min(d_j, n-d_j))
 * としたとき、e_jのヒストグラムを作れば良い。
 * 問題文の残りの部分は、nが素数かつn≡3 (mod 4) のときに、e_jのヒストグラムが
 * 平らになることを主張している。
 */
#include <iostream>
#include <vector>
#include <set>

using namespace std;

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    set<int> s;
    for(int i = 0; i < N-1; ++i) {
        s.insert((i+1)*(i+1) % N);
    }
    vector<int> hist((N-1)/2, 0);
    for(auto it1 = begin(s); it1 != end(s); ++it1) {
        for(auto it2 = begin(s); it2 != it1; ++it2) {
            int e = (*it1 - *it2 + N) % N;
            if(e > (N-1)/2) e = N - e;
            hist[e-1]++;
        }
    }
    for(int i : hist) {
        cout << i*2 << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-9
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;
int main(){
    int n;
    while(scanf("%d",&n),n){
        bool flg[12800]={0};
        vector < int > numbers;
        map <int,int> cnt;
        reps(i,1,n){
            if(flg[(i*i)%n]++)continue;
            numbers.PB((i*i)%n);
        }
        int len = numbers.size();
        sort(numbers.begin(),numbers.end());
        rep(i,len){
            reps(j,i+1,len){
                int tmp = numbers[j]-numbers[i];
                if(tmp > (n-1)/2)tmp = n-tmp;
                cnt[tmp]++;
            }
        }
        map <int,int> :: iterator it;
        for(it = cnt.begin(); it != cnt.end(); it++){
            cout << 2*it->se << endl;
        }
    }
    return 0;
}

C++: #include <stdio.h>

int ans[10001];
int res[10001];

bool ck(int n,int mx){
	return n >= 0 && n <= mx;
}

int main(){
	int n;
	while(scanf("%d",&n), n != 0){
		int mx = (n-1)/2;
		for(int i = 0; i <= n;i++){
			ans[i] = 0;
			res[i] = 0;
		}
		for(int i = 1; i < n; i++){
			long long x = i * i;
			res[x%n]++;
		}
		for(int i = 1;i < n; i++){
			for(int j = i + 1;j < n; j++){
				int dif = i - j;
				while(!ck(dif,mx)){
					if(dif < 0){
						dif += n;
					}
					else if(dif > mx){
						dif = n - dif;
					}
				}
				ans[dif] += res[i] * res[j] > 0 ? 2 : 0;
			}
		}
		for(int i = 1; i <= mx; i++){
			printf("%d\n",ans[i]);
		}
	}

	return 0;
}