g | x | w | all
Bytes Lang Time Link
003APLNARS250512T085243ZRosLuP
009APLDyalog Unicode250510T002703ZMat_rdv
045Juby250506T191126ZJordan
016Arturo221113T113426Zchunes
001Thunno 2 S230614T163431ZThe Thon
nan230214T104200ZThe Thon
062C170908T154516ZHatsuPoi
020K ngn/k221113T125633Zoeuf
003cQuents221113T034412ZStephen
nan220927T182512Zbigyihsu
056Prolog SWI220926T211335ZAiden Ch
nanFig220926T180805ZSeggan
002MathGolf220926T092432ZKevin Cr
027Ruby220926T035926ZnaffetS
073tinylisp220224T214722ZGiuseppe
041Excel VBA170917T194815ZTaylor R
015Factor + math.primes.factors math.unicode220224T222242Zchunes
003Risky220129T063724ZDyad Han
014K ngn/k220130T163344Zcoltim
022Raku220105T024947Zscpchick
042Kotlin220129T111039Zrandom p
002Husk220105T013108ZNatte
001Vyxal s211208T004341Zlyxal
016TIBasic211208T003554ZYouserna
045Python 3211207T183243ZLarry Ba
018x8616 machine code200915T173846Z640KB
015GolfScript200915T163934Z2014MELO
096Rockstar200914T182056ZShaggy
042CasioBasic171011T080059Znumberma
026R170908T003930ZGiuseppe
043Shnap170908T011432ZSocratic
053Clojure170921T220313ZNikoNyrh
096BrainFlak170915T005534ZMegaTom
018Recursiva170908T061526Z0xffcour
029Ruby170915T080705ZG B
009APL170910T214145ZAdalynn
004MY170910T213637ZAdalynn
042Axiom170909T045721Zuser5898
070Batch170908T234808ZNeil
014Mathematica170908T004032ZZaMoC
044Javascript170908T005831Zpowelles
006MATL170908T102533ZCinaski
036PowerShell170908T134312ZAdmBorkB
030Haskell170908T134141Zshooqie
nan170908T131543Zauhmaan
002Jelly170908T003747Zhyperneu
016CJam170908T103932ZLuis Men
020Octave170908T103054ZLuis Men
002Neim170908T101750ZOkx
002Gaia170908T092841ZMr. Xcod
005Husk170908T074322ZMr. Xcod
051Java OpenJDK 8170908T075545ZNevay
002Ohm v2170908T073736ZMr. Xcod
017QBIC170908T072209Zsteenber
006Pyth170908T071354ZMr. Xcod
009Add++170908T063733Zcaird co
002Brachylog170908T063114ZFatalize
023J170908T061016ZJonah
073VBA Excel170908T032235Zremoel
045C gcc170908T015544Ztsh
041Python 2170908T054352ZChas Bro
036Bash + GNU utilities170908T052119ZDigital
005Pari/GP170908T053746Zalephalp
023x8664 Machine Code170908T050350ZCody Gra
044Python170908T014042Ztsh
nanPerl 5170908T040519ZXcali
002RProgN 2170908T021119ZATaco
031JavaScript170908T014257Ztsh
003Japt170908T005458Zpowelles
00205AB1E170908T002959ZH.PWiz

APL(NARS), 3 chars

11π

This above is builtin, without bultin would be something as:

{+/k/⍨∼×⍵∣⍨k←⍳⍵}

16 chars for one algo not scale well with increase of the number of input.

test:

  {+/k/⍨∼×⍵∣⍨k←⍳⍵}20
42
  11π20
42
  11π1
1

APL(Dyalog Unicode), 9 bytes SBCS

+/∘⍸0=⍳|⊢

Try it on APLgolf!

Explanation

        ⊢   right argument (let it be N)
       |    modulo
      ⍳      numbers from 1 to N 
     =   
    0
    0=⍳|⊢   boolean mask for divisors of N
   ⍸        vector of indices (from 1 to N) of 1s in the mask
  ∘         function composition
 /          reduction
+
+/          sum
+/∘⍸0=⍳|⊢    solution

J-uby, 45 bytes

~:^%(:& &:%|~:|&(:>&1)|:+&:select|:|&:+)|:sum

Attempt This Online!

Arturo, 19 16 bytes

$=>[∑factors&]

Try it

Thunno 2 S, 1 byte

F

Attempt This Online!

Or, FS flagless.

Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes

fS

Attempt This Online!

f   # Factors
 S  # Sum

C, C++, C#, D, Java, 65 62 bytes

int d(int n){int s=0,i=1;for(;i<=n;++i)s+=n%i>0?0:i;return s;}

This works in all theses 5 programming languages because of similarities.

C, C++ and D optimization : 62 60 bytes

In C++ and D, integers convert implicitly to booleans ( Zero => false, Not Zero => true ), so you don't need to have the !=0

int d(int n){int s=0,i=1;for(;i<=n;++i)s+=n%i?0:i;return s;}

D optimization : golfy template system, 55 bytes

T d(T)(T n){T s,i=1;for(;i<=n;++i)s+=n%i?0:i;return s;}

C++ optimization by c and c-- : 53 52 bytes

int f(int n,int i=0){return++i<n?f(n,i)+i*!(n%i):n;}

Code to test :

C :

printf("%d %d %d %d %d", d(7), d(15), d(20), d(1), d(5));

C++ :

std::cout << d(7) << ' ' << d(15) << ' ' << d(20) << ' ' << d(1) << ' ' << d(5);

C# :

class FindSum
{
    int d(int n) { int s = 0, i = 1; for (; i <= n; ++i) s += n % i > 0 ? 0 : i; return s; }

    static void Main(string[] args)
    {
        var f = new FindSum();
        Console.WriteLine(string.Format("{0}, {1}, {2}, {3}, {4}", f.d(7), f.d(15), f.d(20), f.d(1), f.d(5)));
    }
}

D :

writeln(d(7));
writeln(d(15));
writeln(d(20));
writeln(d(1));
writeln(d(5));

Java :

public class FindSum {
    int d(int n){int s=0,i=1;for(;i<=n;++i)s+=n%i>0?0:i;return s;}

    public static void main(String[] args) {
        FindSum f = new FindSum();
        System.out.println(String.format("%d, %d, %d, %d, %d", f.d(7), f.d(15), f.d(20), f.d(1), f.d(5)));
    }
}

K (ngn/k), 20 bytes

{+/t(*=(t:1+!x)!'x)}

Try it online!

I honestly didn't know how I manage to make a for-each that find the divisors, lol.

Explanations:

{+/t(*=(t:1+!x)!'x)}  Main function. x is input
    (           'x)   For x amount of times
               !      Modulo it with
       (    !x)       Range, create a list of [0..x-1]
          1+          + 1 to each number in list to turn it into [1..x]
        t:            Assign it to variable t
                      Now, we got the modulo results of each number from [1..x],
                      we now need to
      =               Group them into a dictionary
     *                And get the value of the first key
                      i.e. the occurence positions of the 0s
                      (Implicit at)
   t                  The variable t
 +/                   Sum

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

Go, 62 bytes

func p(n int)(p int){i:=1
for;i<=n;i++{if n%i<1{p+=i}}
return}

Attempt This Online!

-2 bytes compared to my answer to Product of Divisors via use of Go's 0-initialization for variables.

Prolog (SWI), 60 56 bytes

-4 bytes thanks to @Steffan

N+X:-bagof(M,(between(1,N,M),N mod M<1),L),sumlist(L,X).

Try it online!

Fig, \$3\log_{256}(96)\approx\$ 2.469 bytes

+Sk

Try it online!

+Sk
 S  # Sum
  k # The divisors
+   # And add the input

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)

Ruby, 27 bytes

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

Attempt This Online!

Abuses Ruby's nth bit operator.

tinylisp, 74 73 bytes

(load library
(d D(q((K N)(i K(a(i(mod N K)0 K)(D(s K 1)N))0
(q((N)(D N N

Try it online!

-1 byte thanks to DLosc.

And without library just for fun:

tinylisp, 97 90 bytes

(d D(q((N K)(i(l N K)N(D(s N K)K
(d F(q((K N)(i K(a(i(D N K)0 K)(F(s K 1)N))0
(q((N)(F N N

Try it online!

-7 bytes thanks to DLosc.

Excel VBA, 41 Bytes

Anonymous VBE immediate window function that takes input from [A1] and outputs to the VBE immediate window

For i=1To[A1]:s=s-i*([A1]mod i=0):Next:?s

Excel, 41 Bytes

Worksheet formula that takes input from [A1] and outputs to the caller

Requires MS Excel Version 16.0 or later for access to Let(...) function

=LET(a,SEQUENCE(A1),SUM((MOD(A1,a)=0)*a))

Factor + math.primes.factors math.unicode, 15 bytes

[ divisors Σ ]

Try it online!

Risky, 3 bytes

+/?+??

Try it online!

K (ngn/k), 14 bytes

{+/&~1!x%!1+x}

Try it online!

Raku, 25 23 22 bytes

thanks ovs for 2 byte improvement
also JoKing for 1 byte improvement

{sum grep $_%%*,1..$_}
declare anonymous block ($_ implicitly declared)
filter (grep) numbers from 1 to $_ inclusive using the whatever variable (*) that are divisible by $_
get the sum of that list

Try it online!

Kotlin, 42 bytes

{var s=0;for(i in 1..it)if(it%i==0)s+=i;s}

Try it online!

Husk, 2 bytes

ΣḊ

Try it online!

Vyxal s, 1 byte

K

Try it Online!

K∑ flagless. K just gets the divisors of a number.

TI-Basic, 16 bytes

sum(seq(Inot(fPart(Ans/I)),I,1,Ans

Takes input in Ans. Output is stored in Ans and displayed.

Python 3, 45 bytes

lambda n:sum(i for i in range(1,n+1)if n%i<1)

Try it online!

x86-16 machine code, 18 bytes

00000000: 89c1 9988 0e09 0150 d40a 7502 02d4 58e2  .......P..u...X.
00000010: f2c3                                     ..

Listing:

89 C1           MOV  CX, AX                 ; input number as loop counter 
99              CWD                         ; zero DX as running sum 
            DIVLOOP:
88 0E 0109      MOV  BYTE PTR[AAM1+1], CL   ; move loop counter to divisor 
50              PUSH AX                     ; save input number 
            AAM1:
D4 0A           AAM                         ; ZF if (AL % CL == 0), AH = quotient
75 02           JNZ  END_LOOP               ; if not ZF, continue loop 
02 D4           ADD  DL, AH                 ; otherwise add to running sum 
            END_LOOP:
58              POP  AX                     ; restore input number 
E2 F2           LOOP DIVLOOP                ; loop until CL == 0 
C3              RET                         ; return to caller

Callable function, input N in AX, result in DX.

Inspired by @CodyGray's excellent answer, and the comment "It sure seems like there should be a way to make this shorter" I just had to try!

As Cody mentioned, Using DIV/IDIV is inconvenient because it clobbers two registers including the dividend. Another is that the ZF flag is set when the quotient is 0, however in this case we're only interested in when the remainder is 0. Enter AAM, a trusty and underrated byte-sized division/modulo instruction that can be golfy. Even though it does clobber the dividend just like DIV, it will set ZF when the remainder is 0 which is what we want here. It's downside is that the divisor is encoded in the instruction opcode, which can be modified at runtime at a cost of 4 bytes (in real mode at least).

GolfScript, 15 bytes

~.,{.3$\%!*+}*+

Try it online!

~                # Parses the input to integer
 .,              # Makes an array with numbers from 0 to (N-1)
   {.3$\%!*+}    # This block goes to the top of the stack without being executed
             *   # Folds
              +  # Adds the input and the result

What the block does:

    .            # Duplicates the number of the array
     3$          # Makes a copy of N
       \%!       # Tests if the number of the array is a divisor of N
          *      # Multiplies, resulting in the divisor if it was divisible or 0 if it wasn't
           +     # Adds to the acumulator

Rockstar, 96 bytes

listen to N
X's0
T's0
while N-X
let X be+1
let D be N/X
turn up D
let T be+D is N/X and X

say T

Try it here (Code will need to be pasted in)

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.

R, 31 26 bytes

function(N)(x=1:N)%*%!N%%x

Try it online!

Returns a 1x1 matrix.

Computes !N%%x maps elements d of 1:N by: d->(1 if d divides N, 0 otherwise)

Then x%*%x!N%%x is the matrix product of 1:N which results in the sum of x where !N%%x is 1. Neat! Technically a port of Luis Mendo's Octave answer but I only saw that after I thought of this.

R+ numbers, 14 bytes

numbers::Sigma

Try it online!

Shnap, 44 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

 $n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n                        //Start function with parameter n
    return: {              //Technically, we are returning a scope-block, which evaluates to the last statement run
        s = 0              //Our result
        for d : range(n+1) //For each value in the iterator range(n+1)
            if n % d < 1  // If n is divisible by d
                s += d     // Add d to the sum
                           // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
    }

Noncompeting, 19 bytes

After many language updates, this can now be reduced to a measly 19 bytes:

$n=>sum(factors(n))

Try it online!

Clojure, 53 bytes

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

Brain-Flak, 96 bytes

((({})<>){<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

Try it online!

Explanation:

Now outdated by improvements.

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

((({})<>) place input, N on both stacks
{ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum

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

Ruby, 29 bytes

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

Try it online!

APL, 9 bytes

+/⍳×0=⍳|⊢

Try it online!

How? (input n)

MY, 4 bytes

ωḊΣ↵

Try it online!

How?

It's really simple: ω is the argument, is divisors, Σ is sum, is output. I thought I already answered this challenge, for some reason.

Axiom, 42 bytes

f(x:PI):PI==(x=1=>1;reduce(+,divisors(x)))

results

(19) -> [[i,f(i)] for i in [7,15,20,42,1,5] ]
   (19)  [[7,8],[15,24],[20,42],[42,96],[1,1],[5,6]]
                                          Type: List List PositiveInteger

Batch, 70 bytes

@set/ai=%2+1,s=%3+i*!(%1%%i)
@if not %i%==%1 %0 %1 %i% %s%
@echo %s%

Alternative solution, also 70 bytes:

@set s=0
@for /l %%i in (1,1,%1)do @set/as+=%%i*!(%1%%%%i)
@echo %s%

Mathematica, 14 bytes

Tr@Divisors@#&   

or an answer by @Loki

Mathematica, 17 bytes

DivisorSum[#,#&]&

Javascript, 54 44 bytes

n=>[...Array(x=n)].reduce(y=>y+!(n%x)*x--,0)

Saved 10 bytes thanks to Shaggy

Try it online!

const f = n=>[...Array(x=n)].reduce(y=>y+!(n%x)*x--,0)

console.log(f(7))
console.log(f(15))
console.log(f(20))
console.log(f(1))
console.log(f(5))

MATL, 6 bytes

t:\~fs

Try it online!

-4 bytes thanks to @LuisMendo

10 bytes

My previous solution using a loop

:"G@\~@*vs

Try it online!

3 bytes

Using built-in

Z\s

Try it online!

PowerShell, 36 bytes

param($a)1..$a|%{$j+=$_*!($a%$_)};$j

Try it online!

Explanation

param($a)1..$a|%{$j+=$_*!($a%$_)};$j
param($a)                            # Takes input $a
         1..$a|%{               };   # For-loop from 1 up to $a
                          $a%$_      # Modulo, if this is zero we've hit a divisor
                        !(     )     # Take the Boolean-not of that. If a divisor, it's 1
                     $_*             # Multiply the current number by that Boolean
                                     # Only if it's a divisor will this be non-zero
                 $j+=                # Add it into our accumulator
                                  $j # Output our accumulator

Haskell, 30 bytes

f n=sum[i|i<-[1..n],n`mod`i<1]

Try it online!

C#, 56 bytes


Data


Golfed

i=>{int s=0,d=1;for(;d<=i;d++)s+=i%d<1?i/d:0;return s;};

Ungolfed

i => {
    int
        s = 0,
        d = 1;
        
    for( ; d <= i; d++ )
        s += i % d < 1 ? i / d : 0;
    
    return s;
};

Ungolfed readable

// Takes an int
i => {
    // Initializes the sum 's' and divider 'd' vars
    int
        s = 0,
        d = 1;
        
    // Cycles each number lower than the the number 'i'
    for( ; d <= i; d++ )
    
        // Sums the result of the division between 'i' and 'd' if the modulus is 0
        s += i % d < 1 ? i / d : 0;
    
    // Returns the sum
    return s;
};

Full code

using System;
using System.Collections.Generic;

namespace TestBench {
    public class Program {
        // Methods
        static void Main( string[] args ) {
            Func<Int32, Int32> f = i => {
                int s = 0, d = 1;

                for( ; d <= i; d++ )
                    s += i % d < 1 ? i / d : 0;

                return s;
            };

            List<Int32>
                testCases = new List<Int32>() {
                    7,
                    15,
                    20,
                    42,
                    1,
                    5,
                };

            foreach( Int32 testCase in testCases ) {
                Console.WriteLine( $" INPUT: {testCase}\nOUTPUT: {f( testCase )}" );
            }

            Console.ReadLine();
        }
    }
}

Releases


Notes

Jelly, 2 bytes

Æs

Try it online!

Built-in that does exactly as wanted.

CJam, 16 bytes

ri:X{)_X\%!*}%:+

Try it online!

Explanation

ri                 e# Read integer, n
  :X               e# Write to variable X
    {       }%     e# Map this block over the array [0 1 ... n-1]
     )             e# Increment current value. Will give 1, 2, ..., n
      _            e# Duplicate
       X           e# Push input
        \          e# Swap
         %         e# Modulus
          !        e# Negate
           *       e# Multiply
              :+   e# Sum of array. Implicitly display

Octave, 20 bytes

@(n)~mod(n,t=1:n)*t'

Try it online!

Neim, 2 bytes

𝐅𝐬

Try it online!

Gaia, 2 bytes

Try it online!

Pretty straight-forward:

dΣ   - Full program.

d    - Divisors.
 Σ   - Sum.

Husk, 5 bytes

ṁΠuṖp

Try it online!

How?

ṁΠuṖp  - Full program, implicit input.

     p  - Prime factors.
    Ṗ   - Powerset.
   u    - Remove duplicates.
ṁΠ     - Get the product of each list, sum and implicitly output.

Thanks to Zgarb for the suggestions in chat!

Java (OpenJDK 8), 53 51 bytes

n->{int s=0,i=0;for(;i++<n;)s+=n%i<1?i:0;return s;}

Try it online!

Ohm v2, 2 bytes

Try it online!

This is pretty straight-forwad:

V   - Divisors.
 Σ  - Sum.

QBIC, 17 bytes

[:|~b%a|\p=p+a}?p

Explanation

[:|      FOR a = 1; a <= b (read from cmd line); a++
~b%a|    IF b modulo a has a remainder THEN - empty block - 
\p=p+a   ELSE add divisor 'a' to running total 'p'
}        END IF, NEXT
?p       PRINT p

Pyth, 6 bytes

s*M{yP

Try it here!

Pyth doesn't have a built-in for divisors, so I think this is reasonable.

Explanation

s*M{yP    - Full program with implicit input.

     P    - The prime factors of the input.
    y     - The powerset of its prime factors.
   {      - Deduplicate.
 *M       - Map with multiplication.
s         - Sum.
          - Implicitly display the result.

Given 20, for instance, this is what our program does after each instruction:

Add++, 9 bytes

D,f,@,dFs

Try it online!

I clearly got here too late. This defines a function that gets the factors, then sums them.

Brachylog, 2 bytes

f+

Try it online!

Explanation

f       Factors
 +      Sum

J, 23 bytes

[:+/](([:=&0]|[)#])1+i.

Try it online!

For J fans, there is a clever 13 byte solution: >:@#.~/.~&.q: but since it wasn't my invention I'm not posting it as my official answer.

My own solution simply filters 1..n, finding divisors, then sums them. The crux of it is the dyadic fork

](([:=&0]|[)#])

Note that in this context ] is 1..n, and [ is n itself. Hence ]|[ are the remainders when dividing each element of 1..n into n, and =&0 tells you if they're equal to 0.

VBA (Excel), 73 bytes

a=Cells(1,1)
x=1
While x<=a
If a Mod x = 0 Then b=b+x
x=x+1
Wend
MsgBox b

C (gcc), 45 bytes

i,s;f(n){for(s=i=n;--i;)s+=n%i?0:i;return s;}

Try it online!

Python 2, 41 bytes

f=lambda n,i=1:i<=n and(n%i<1)*i+f(n,i+1)

Try it online!

Bash + GNU utilities, 36

bc<<<`seq -f"n=%g;a+=n*!$1%%n;" $1`a

Try it online.


Pure Bash, 41

for((;++i<=$1;a+=$1%i?0:i))
{
:
}
echo $a

Try it online.

I first tried a fancy bash expansion answer, but it ended up being longer than the simple loop above:

echo $[$(eval echo +\\\(n={1..$1},$1%n?0:n\\\))]

Pari/GP, 5 bytes

sigma

Try it online!

x86-64 Machine Code, 23 bytes

89 F9 89 FE EB 0D 89 F8 99 F7 F1 85 D2 99 0F 44 D1 01 D6 E2 F1 96 C3

The above bytes of code define a function that accepts a single integer, N, and returns the sum of its multiples as a result.

The single parameter is passed in the EDI register, consistent with the System V AMD64 ABI (as used on *nix-style systems). The result is returned in the EAX register, as with all x86 calling conventions.

The algorithm is a very straightforward one, similar to many of the other submissions in other languages. We loop N times, each time computing the modulo and adding that to our running total.

Ungolfed assembly mnemonics:

; unsigned SumOfMultiples(unsigned N  /* (EDI) */)
    mov     ecx, edi      ; make copy of input N, to be used as our loop counter
    mov     esi, edi      ; make copy of input N, to be used as our accumulator
    jmp     CheckEnd      ; jump directly to 'CheckEnd'
AddModulo:
    mov     eax, edi      ; make copy of input N, to be used as input to DIV instruction
    cdq                   ; short way of setting EDX to 0, based on EAX
    div     ecx           ; divide EDX:EAX by ECX, placing remainder in EDX
    test    edx, edx      ; test remainder, and set ZF if it is zero
    cdq                   ; again, set EDX to 0, without clobbering flags
    cmovz   edx, ecx      ; set EDX to ECX only if remainder was zero (EDX = ZF ? 0 : ECX)
    add     esi, edx      ; add EDX to accumulator
CheckEnd:
    loop    AddModulo     ; decrement loop counter (ECX), and keep looping if it != 0
    xchg    eax, esi      ; move result from accumulator (ESI) into EAX
    ret                   ; return, with result in EAX

Try it online!

It sure seems like there should be a way to make this shorter, but I can't see it. Computing modulo on x86 takes quite a bit of code, since you do it using the DIV (or IDIV) instruction, and both of those use fixed input registers (EDX and EAX), the values of which get clobbered (because they receive the results, the remainder and quotient, respectively).

The only real tricks here are pretty standard golfing ones:

Python, 44 bytes

lambda k:sum(i*(k%i<1)for i in range(1,1+k))

Perl 5, 35 + 1 (-p) = 36 bytes

$\+=($n%$_==0)&&$_ for 1..($n=$_)}{

Try it online!

RProgN 2, 2 bytes

ƒ+

Explained

ƒ+
ƒ   # Factorize
 +  # Sum

Trivial, but felt it needed to be posted.

Try it online!

JavaScript, 31 bytes

f=(n,i=n)=>i&&!(n%i)*i+f(n,i-1)

Japt, 3 bytes

â)x

Try it online!

05AB1E, 2 bytes

ÑO

Try it online!

How?

Ñ    Divisors
 O   Sum