Edit : Dang, I failed the interview! :-( In my zealous attempt to find tricks or heuristics in order to improve "factorization decomposition + list divisors + sum them", I did not notice that being 1 modulo 9 was simply necessary and, of course, not a sufficient condition for a number (other than 6) to be perfect ...
Duh ... on average, for 1 out of 9 even numbers that satisfy this condition, my algorithm will probably find a few too many perfect numbers ;-).
To redeem yourself, save and support the proposal to use the digital root, but only as a filter to avoid a more expensive factor calculation in most cases.
[Initial Attempt: Hall of Shame]
If the number is even,<br> compute its [digital root][1]. if the digital root is 1, the number is perfect, otherwise it isn't. If the number is odd... there are no shortcuts, other than... "Not perfect" if the number is smaller than 10^300 For bigger values, one would then need to run the algorithm described in the question, possibly with a few twists typically driven by heuristics that prove that the sum of divisors will be lacking when the number doesn't have some of the low prime factors.
My reason for offering a digital root trick for even numbers is that this one can be computed without using an arbitrary arithmetic length library (like GMP). It is also much less computationally expensive than factorization and / or factorization (2 ^ (p-1) * ((2 ^ p) -1)). Therefore, if the interviewer should be satisfied with a "perfect" answer to odd numbers, the solution will be very effective and compatible in most computer languages.
[Second and third attempt ...]
If the number is even,<br> if it is 6 The number is PERFECT otherwise compute its [digital root][1]. if the digital root is _not_ 1 The number is NOT PERFECT else ..., Compute the prime factors Enumerate the divisors, sum them if the sum of these divisor equals the 2 * the number it is PERFECT else it is NOT PERFECT If the number is odd... same as previously
About this relatively odd interview question ...
Andrewdski's second comment on another answer in this post is that this particular question is rather strange in the context of an interview for a general-purpose developer. As in many questions of the interview, perhaps the interviewer is not looking, but rather gives the candidate the opportunity to demonstrate his ability to formulate common advantages and disadvantages of various approaches. In addition, if the candidate is offered the opportunity to search for common resources, such as MathWorld or Wikipedia, before answering, this can also be a good test of his ability to quickly comprehend the information offered there.