Armstrong Numbers

1179
Tempo Limite: 10 | Nível: 4

Descrição

An integer number is known as an Armstrong Number when we take each one of its digits to the power of an integer n and with the sum of the results we get the original number. For example, 153 is an Armstrong Number with base 3, because 13 + 53 + 33 = 1 + 125 + 27 = 153. The integer 54748 is an Armstrong Number with base 5 because 55 + 45 + 75 + 45 + 85 = 3125 + 1024 + 16807 + 1024 + 32768 = 54748. Your task in this problem is to verify if an integer number is a rare Armstrong Number.


Entrada

The input has many integers between 2 and 1000000000, each number must be verified if it is an Armstrong Number in some base. Consider in this problem that we want to identify numbers that fits the criteria described above only on bases bigger than 1 and smaller than 10. The program should finish reading the input after a zero is read.


Saída

For each test case, print a letter N (uppercase) if the integer read isn´t an Armstrong Number with base between 2 and 9. Otherwise, print the base found for the input. If it was possible to find an Armstrong Number with more than one base, print the smallest.


Exemplos de Entrada Exemplos de Saída

1234
153
370
371
407
201
54748
0

N
3
3
3
3
N
5

Efetue Login ou Cadastre-se para submeter uma solução.



Criado por Antonio Cesar de Barros Munari (Fatec Sorocaba) | Adaptado por erich.rodriguesf | Competição: Interfatecs 2015