Sum of divisors P95972


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

thehtml

Write a function that returns the sum of the divisors of a number n.

For instance, the sum of the divisors of 28 is 1+2+4+7+14+28 = 56.

Interface

C++,C
int sum_divisors(int x);
Java
public static int sumDivisors(int x);
Python
sum_divisors(x) # returns int
 
sum_divisors(x: int) -> int

Precondition

1 ≤ n ≤ 108.

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    sum_divisors(28) → 56
    sum_divisors(1) → 1
    sum_divisors(100) → 217
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C C++ Java Python
    User solutions
    C C++ Java Python