#include <iostream>
using namespace std;

const int SIZE = 1000000;
const int MAXNUMFACTORS = 9;

int factors[SIZE+1][MAXNUMFACTORS];
int numFactors[SIZE+1];
int vals[MAXNUMFACTORS];

int used[SIZE+1];
int last = 2;
int Count = 2;
int start[SIZE+1];

void getAllFactors()
{
	for(int n=2; n<=SIZE; n++) {
		numFactors[n] = 0;
		if (n%2 == 0)
			factors[n][numFactors[n]++] = 2;
		if (n%3 == 0)
			factors[n][numFactors[n]++] = 3;
	}
	int factor = 5;
	while (factor <= SIZE) {
		if (numFactors[factor] == 0) {
			for(int n=factor; n<=SIZE; n+=factor) {
				factors[n][numFactors[n]++] = factor;
			}
		}
		factor += 2;
		if (numFactors[factor] == 0) {
			for(int n=factor; n<=SIZE; n+=factor) {
				factors[n][numFactors[n]++] = factor;
			}
		}
		factor += 4;
	}
}

void getFactors(int n)
{
	for(int i=0; i<numFactors[n]; i++) {
		vals[i] = start[factors[n][i]];
	}
}

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a%b);
}

int getMin()
{
	int index = 0;
	int min = vals[index];
	for(int i=1; i<numFactors[last]; i++) {
		if (vals[i] < min) {
			index = i;
			min = vals[i];
		}
	}
	for(int i=0; i<numFactors[last]; i++)
		if (vals[i] == min)
			vals[i] += factors[last][i];
	return min;
}

int nextNum(int m)
{
	int min = getMin();
	while (min <= SIZE) {
		if (used[min] == -1)
			return min;
		min = getMin();
	}
	cout << "Error, value exceeded " << SIZE << ", last = " << m << endl;
	exit(-1);
}
	
int solve(int n)
{
	if (used[n] != -1)
		return used[n];
	getFactors(last);
	while (true) {
		last = nextNum(last);
		used[last] = ++Count;
		getFactors(last);
		for(int i=0; i<numFactors[last]; i++) {
			if (last == start[factors[last][i]]) {
				while(used[start[factors[last][i]]] != -1) {
					start[factors[last][i]] += factors[last][i];
					if (start[factors[last][i]] > SIZE) {
						start[factors[last][i]] -= factors[last][i];
						break;
					}
				}
			}
		}
		if (last == n)
			break;
	}
	return used[n];
}

int main()
{
	getAllFactors();
	int n;
	cin >> n;

	for(int i=1; i<=SIZE; i++) {
		used[i] = -1;
		start[i] = i;
	}
	used[1] = 1;
	used[2] = 2;
	start[2] = 4;
	while (n > 0) {
		cout << "The number " << n << " appears in location " << solve(n) << '.'<<endl;
		cin >> n;
	}
 return 0;
}
