TopcoderArchive
Archive
Algorithm problem

PerfectNumbers

Problem statement, definition, constraints, and public examples.

Problem Statement

Let X and Y be positive integers. We say that Y is a divisor of X if and only if there is a positive integer Z such that X = Y*Z.

You will be given a String[] numbers. Each element in this String[] will contain a positive integer. For each of the given integers compute the sum of its positive divisors, itself excluded. Return a String[] containing the computed sums in the same order, with no unnecessary leading zeroes.

Definition

Class:
PerfectNumbers
Method:
sumDivisors
Parameters:
String[]
Returns:
String[]
Method signature:
String[] sumDivisors(String[] numbers)
(be sure your method is public)

Notes

  • All the numbers in the input, and all the numbers you should output will fit into 64-bit signed integer variables.

Constraints

  • numbers will contain between 1 and 50 elements, inclusive.
  • Each element in numbers contains between 1 and 13 digits ('0'-'9'), inclusive.
  • No element in numbers will contain leading zeroes.

Examples

  1. {"6"}
    Returns: {"6" }
    The divisors of 6 (other than 6 itself) are 1, 2, and 3. Their sum is 1+2+3 = 6.
  2. {"28"}
    Returns: {"28" }
    Divisors of 28 are 1, 2, 4, 7, and 14, and their sum is 1+2+4+7+14 = 28.
  3. {"4", "8", "16", "32"}
    Returns: {"3", "7", "15", "31" }
  4. {"13", "47", "997"}
    Returns: {"1", "1", "1" }
  5. {"510510"}
    Returns: {"1231314" }
    510510 = 2*3*5*7*11*13*17
  6. {"235152", "235326326132", "1234567890123"}
    Returns: {"461232", "176530725964", "411987510213" }
  7. {"9999999999999"}
    Returns: {"4903272088641" }
    This is the largest valid input number.
  8. {"1"}
    Returns: {"0" }
    And this is the smallest valid input.
Back to all problems