Federation Favorites
InterviewTime limit1sMemory limit256 MB
Read integers until -1 and print each perfect number with its divisors or state that it is not perfect.
- Level
Easy3 of 10
- Topics
- Number theory, Implementation
- Solved
- No attempts yet
Problem
On the way to Rigel 7, chief engineer Geordi and Data compared their favorite numbers. Geordi said he likes narcissistic numbers: a number that equals the sum of its own digits, each digit raised to the power of the number of digits.
Data answered that narcissistic numbers are interesting but not as good as his own favorite, perfect numbers. Geordi had never heard of a perfect number, so Data explained. A positive integer is perfect if it equals the sum of its positive divisors smaller than itself. 6 is perfect because 6 = 1 + 2 + 3.
Geordi started working out how to decide whether a number is perfect, but he does not compute as fast as Data. Write the program for him.
Input
The input holds one number per line. Each line contains a positive integer with . A line containing -1 marks the end of the input and is not processed.
Output
For each , decide whether it is perfect. If is perfect, print the number, an equals sign, and its positive divisors smaller than the number in ascending order, in the form n = d1 + d2 + ... + dk. If is not perfect, print <NUM> is NOT perfect. where <NUM> is that number. Separate every word, symbol, and number in the output with a single space. The period that ends the sentence for a number that is not perfect is the only exception.