ZeroJudge I025: Sum of Proper Divisor

A proper divisor, or proper factor, of a natural number, is a factor of a number other than 1 and the number itself. For example, the proper divisors of 6 are 1, 2, and 3.

Given a positive integer, find its sum of proper divisors.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The input consists of only one line containing a positive integer N (1 ≤ N ≤ 65535).Output the sum of the proper divisors of N.
66
1216

Thought Process

Use a for loop from 1 to N - 1 (excluding N itself). Since the number is not large, you can directly iterate through all the divisors of N and sum them up. Finally, output the sum of the divisors.

Sample Code-ZeroJudge I025: Sum of Proper Divisor

#include <iostream>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i<N; i++)
    {
        if (N % i == 0) ans += i;
    }
    cout << ans << "\n";
}

//Z.O.J. I025
//Dr. SeanXD

Comments