Sum of Proper Divisors
EasyPractice library · +10 XPmathnumber theory
Given a positive integer N, compute the sum of all its positive divisors, excluding N itself. These divisors are often called the proper divisors.
Input
A single line containing a positive integer N.
Output
A single integer representing the sum of the proper divisors of N.
Constraints
1 <= N <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
12
Output
16
The proper divisors of 12 are 1, 2, 3, 4, 6. Their sum is 1 + 2 + 3 + 4 + 6 = 16.
Example 2
Input
28
Output
28
The proper divisors of 28 are 1, 2, 4, 7, 14. Their sum is 1 + 2 + 4 + 7 + 14 = 28. (28 is a perfect number)
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
12
Example 2 input
28