Sum of Divisors
EasyPractice library · +10 XPmathnumber theory
Given a positive integer N, compute the sum of all its positive divisors, including 1 and N itself. For example, the divisors of 6 are 1, 2, 3, and 6. Their sum is 1 + 2 + 3 + 6 = 12.
Input
A single line containing a positive integer N.
Output
A single line containing the sum of all positive divisors of N.
Constraints
1 <= N <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests
Example 1
Input
6
Output
12
The divisors of 6 are 1, 2, 3, and 6. The sum is 1 + 2 + 3 + 6 = 12.
Example 2
Input
10
Output
18
The divisors of 10 are 1, 2, 5, and 10. The sum is 1 + 2 + 5 + 10 = 18.
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
6
Example 2 input
10