ZeroJudge C203: DPA Numbers I

UVa 13185 – DPA Numbers I

An integer B is called a factor of another integer A (where A > B) if A is divisible by B.

A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself).

For example, 6 and 28 are both perfect numbers because 6 = 1 + 2 + 3, and 28 = 1 + 2 + 4 + 7 + 14.

If a positive integer is not perfect, then it is either deficient or abundant, depending on whether the sum of its proper divisors is less than or greater than the number itself. Therefore, 9 is deficient because 1 + 3 12.

Please write a program to determine whether a given number is Perfect, Deficient, or Abundant.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line of input contains a positive integer t, representing the number of test cases to follow. (1 <= T <= 500)
Each test case consists of a single line containing a positive integer N. (2 <= N <= 1000)
For each test case, output a single line indicating whether N is Perfect, Deficient, or Abundant.
10
5
6
16
18
21
28
29
30
40
43
deficient
perfect
deficient
abundant
deficient
perfect
deficient
abundant
abundant
deficient

Thought Process

Use a for loop to iterate over each number as a potential divisor. If the remainder of N divided by the current number (i) is 0, then i is a divisor of N. After summing up the divisors, determine whether it is less than, equal to, or greater than N.

Sample Code-ZeroJudge C203: DPA Numbers I

#include <iostream>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    for (int i = 0; i<T; i++)
    {
        int N;
        cin >> N;
        int count = 0;
        for (int j = 1; j<N; j++)
        {
            if (N % j == 0)
            {
                count += j;
            }
        }
        if (count == N) cout << "perfect\n";
        else if (count > N) cout << "abundant\n";
        else cout << "deficient\n";
    }
}

//ZeroJudge C203
//Dr. SeanXD

Comments