TopcoderArchiveVisit Topcoder
SRM29 Aug 2001
SRM 27

KPerfect

Problem statement, definition, constraints, and public examples.

Problem Statement

Class name: KPerfect
Method name: abundancy
Parameters: int
Returns: int


If f(n) denotes the sum of all integer divisors of n and f(n) = k * n then n is
a k-fold perfect number where k is an integer. The sum of all integer divisors
of n is defined as the sum of positive integers less than or equal to n that
divide n with a remainder of zero.


The integer coefficient k above is known as the abundancy of n.


Write a class KPerfect, which contains a method abundancy. The method should
accept an integer as a parameter and return its abundancy as defined above. If
the input is not a k-fold perfect number, the method should return 0.


The method signature is (Be sure your method is public):
int abundancy (int n);


* n will satisfy 1 <= n <= 1,000,000;


For Example, if n = 6, f(n) = 1 + 2 + 3 + 6 = 12. f(n) = k * n -> 12 = 2 * 6
k = 2.


Examples:
n = 1    result: 1
n = 6    result: 2
n = 120  result: 3
n = 154  result: 0

Definition

Class:
KPerfect
Method:
abundancy
Parameters:
int
Returns:
int
Method signature:
int abundancy(int param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems