#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		set<int> Set;
		for(int i = 1; i < n; ++i)
		{
			Set.insert((i * i) % n);
		}
		vector<int> num;
		set<int>::iterator it = Set.begin();
		while(it != Set.end())
		{
			num.push_back(*it);
			++it;
		}
		vector<int> diff;
		for(int i = 0; i < num.size(); ++i)
		{
			for(int j = 0; j < num.size(); ++j)
			{
				if(i == j)
				{
					continue;
				}
				int temp = num[i] - num[j];
				if(temp < 0)
				{
					temp += n;
				}
				if(temp > (n - 1) / 2)
				{
					temp = n - temp;
				}
				diff.push_back(temp);
			}
		}
		sort(diff.begin(), diff.end());
		int now = diff[0];
		int count = 1;
		for(int i = 1; i < diff.size(); ++i)
		{
			if(diff[i] != now)
			{
				cout << count << endl;
				now = diff[i];
				count = 1;
			}
			else
			{
				++count;
			}
		}
		if(count >= 2)
		{
			cout << count << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}