Find the sum of the divisors of N

Write a program that displays on the screen the sum of the divisors of a number (1 ≤ N ≤ 100) entered by the user in the range of 1 to N.

This is OEIS A000203.

Examples:

Input: 7

7 / 1 = 7
7 / 7 = 1

7 + 1 = 8


Output: 8

Input: 15

15 / 1 = 15
15 / 3 = 5
15 / 5 = 3
15 / 15 = 1

15 + 5 + 3 + 1 = 24


Output: 24

Input: 20

20 / 1 = 20
20 / 2 = 10
20 / 4 = 5
20 / 5 = 4
20 / 10 = 2
20 / 20 = 1

20 + 10 + 5 + 4 + 2 + 1 = 42


Output: 42

Input: 1

1 / 1 = 1


Output: 1

Input: 5

5 / 1 = 5
5 / 5 = 1

5 + 1 = 6


Output: 6

• @H.PWiz I think he means "the divisors of a number N" Sep 8, 2017 at 0:18
• I think you mean sum of divisors, aka, the sigma function? Sep 8, 2017 at 0:18
• Sorry, i mean "The sum of the multiple of N". Sep 8, 2017 at 0:19
• @H.PWiz this is the sum of those, so I dunno Sep 8, 2017 at 0:21
• @Stephen That seems like a trivial change to me Sep 8, 2017 at 0:21

Ruby, 29 bytes

->x{(1..x).sum{|r|x%r>0?0:r}}


Try it online!

Recursiva, 20 18 bytes

smBa++'%'Va'a:0!a'


Try it online!

Explanation:

smBa++'%'Va'a:0!a' - Input to a; 20
s                    - sum up; 42
m                   - map with; [1, 0, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]
Ba                 - Range; [1,2..20]
++'%'Va'a:0!a'   - function, evaluates to 0 if param cannot divide a i.e. 20


Clojure, 53 bytes

#(apply +(for[i(range 1(inc %)):when(=(mod % i)0)]i))


Casio-Basic, 42 bytes

sum(seq(piecewise(n/x=int(n/x),x,0),x,1,n


The piecewise acts as a shorter If statement. seq loops values of x from 1 to n, and the piecewise returns x if the number is a factor, otherwise it returns 0. sum adds the whole list together to output the total.

41 bytes for the function, +1 to add n in the parameters box.

Ruby, 27 bytes

->x{(1..x).sum{1[x%_1]*_1}}


Attempt This Online!

Abuses Ruby's nth bit operator.

MathGolf, 2 bytes

─Σ


One of many 2-bytes answers in a code-golf language.

Try it online.

Explanation:

─   # Get a list of divisors of the (implicit) input-integer
Σ  # Sum them together
# (after which the entire stack is output implicitly as result)


cQuents, 3 bytes

Uz$ Try it online! Explanation  implicit mode sequence - print nth term in sequence given input n U sum ( ) z divisors ( )$                   current term