g | x | w | all
Bytes Lang Time Link
003Vyxal 3250808T124048ZThemooni
044Setanta250807T195146Zbb94
028AWK250807T165915Zxrs
012K ngn/k231103T115939Zcoltim
225Malbolge Unshackled231103T112714ZKamila S
008APLDyalog Unicode231019T091833ZKamila S
007Uiua231016T004011Zchunes
021Arturo230612T192927Zchunes
045Trilangle230612T191212ZBbrk24
091Rockstar230612T101000ZShaggy
002Thunno 2 S230611T165149ZThe Thon
020Mathematica221009T200642Zhakr14
052Nim221009T195738ZnaffetS
016Julia 1.0221009T193832ZAshlin H
nan221007T144911Zbigyihsu
016K ngn/k221007T141842Zoeuf
027Rust221007T012337Zmanatwor
024Juby221006T234317ZJordan
030PowerShell Core210621T230525ZJulian
013Ly210619T234503Zcnamejj
030Knight210620T012626ZEasyasPi
033Factor + math.unicode210620T020958Zchunes
003Vyxal210619T223825ZUndersla
328MMIX210619T221425ZNoLonger
038Labyrinth200924T063312ZBubbler
023Ruby180821T094755Zlynn
009Brachylog180821T092933ZKroppeb
021Ahead180821T054801Zsnail_
035F#180820T201834ZCiaran_M
031dc180820T183932Zbrhfl
003Japt mx180820T180633ZLuis fel
035Forth gforth180820T164808Zreffu
061PHP171217T205133ZNK1406
023Ruby171214T014813ZJordan
068SNOBOL4 CSNOBOL4171214T203008ZGiuseppe
044Python 2171219T080642ZMax00355
079TSQL171214T175352ZBrian J
013Pushy171218T173200ZFlipTack
036Befunge93171218T165024ZJo King
047Common Lisp171218T153701ZRenzo
039Clean171216T073411ZΟurous
062BrainFlak171215T023900ZNitrodon
014J171216T040437ZBolce Bu
063Windows Batch CMD171214T092030ZNeil
045Labyrinth 45 Characters171215T232943ZC Anders
016Perl 6171214T180449ZSean
025Funky171215T032505ZATaco
038Clojure171214T220722ZNikoNyrh
0674171214T213217ZUriel
005Japt171214T020033ZETHprodu
009J171214T085914ZGalen Iv
008Gaia171214T190839ZGiuseppe
019MATLAB171214T175030Zbrainkz
014Add++171214T173323Zcaird co
015Julia 0.4171214T162039ZLescurel
017Pari/GP171214T132158Zalephalp
005APL Dyalog171214T123940ZUriel
010APL+WIN171214T123423ZGraham
018Mathematica171214T113031Ztotallyh
045Java OpenJDK 8171214T110246ZOlivier
003Neim171214T103231ZLiefdeWe
023Ruby171214T094912ZG B
007Pip171214T092616ZDLosc
020R171214T092505Zplannapu
051Standard ML MLton171214T085437ZLaikoni
004MATL171214T081646ZSanchise
004Ohm v2171214T080633ZCinaski
009Charcoal171214T074540ZCharlie
00305AB1E171214T052701ZMr. Xcod
005Pyth171214T025548ZDave
022Haskell171214T030308Zბიმო
nanPerl 5171214T030018ZXcali
00605AB1E171214T021452ZShieru A
005Husk171214T015643Zბიმო
037Python 3171214T013111ZNeil
026JavaScript ES6171214T013026ZArnauld
043C171214T013005ZSteadybo
003Jelly171214T012551Zdylnan

Vyxal 3, 3 bytes

ɾ%∑

Vyxal It Online!

ɾ%∑­⁡​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌­
ɾ    # ‎⁡range 1..implicit input
 %   # ‎⁢vectorized mod implicit input
  ∑  # ‎⁣sum
💎

Created with the help of Luminespire.

<script type="vyxal3">
ɾ%∑
</script>
<script>
    args=["1", "2", "3", "4", "5", "6", "7", "8", "9"]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>

Setanta, 44 bytes

gniomh(n){t:=0le i idir(1,n)t+=n%i toradh t}

try-setanta.ie link

AWK, 28 bytes

{for(;i++<$1;)x+=$1%i}1,$0=x

Attempt This Online!

K (ngn/k), 13 12 bytes

-1 byte from @ovs' improvement

+/1_!'/|1!:\

Try it online!

Malbolge Unshackled, 1,828,225 bytes.

Available on GitHub as StackExchange does not allow posting answers this long.

Use as, having obtained fast20 or any Malbolge Unshackled interpreter:

$ echo -ne "\xFF" | time ./fast20 150563.mb | xxd
00000000: c3

APL(Dyalog Unicode), 8 bytes SBCS

+/⊢|⍨1↓⍳

Try it on APLgolf!

Uiua, 7 bytes

/+◿+1⇡.

Try it!

/+◿+1⇡.
      .  # duplicate
     ⇡   # range
   +1    # plus one
  ◿      # mod
/+       # sum

Arturo, 21 bytes

$->n[∑map n'x->n%x]

Try it!

Trilangle, 45 bytes

<'?0'1...Lj2'<.zj2'.......L-)S+%,7#..@!,,,/^S

Try it on the online interpreter!

TODO: add colorized explanation

<'?0'1...Lj2'<.zj2'.......L-)S+%,7#..@!,,,/^S

  ?                                           Get number from stdin
   0'                                         Start sum at 0
 '   1                                        Start counter at 1
          j2'  zj2'       L-     7            Compare the counter and the input
                                     @!,,,/   If they're the same, print the sum and exit
                            )S+%,           S Otherwise, add one iteration and increment the counter
             <      .             #        ^  Loop

Rockstar, 91 bytes

listen to N
D's 0
O's 0
while N-D
let D be+1
let M be N/D
turn M down
let O be+N-M*D

say O

Try it (Code will need to be pasted in)

Thunno 2 S, 2 bytes

R%

Attempt This Online!

Explanation

R%  # Implicit input.
R   # Range. Push [1..input].
 %  # Mod. Vectorises.
    # S flag sums.
    # Implicit output.

Mathematica, 20 bytes

Sum[Mod[#,i],{i,#}]&

View it on Wolfram Cloud!

Nim, 52 bytes

import sugar,sequtils
n=>toSeq(1..n).foldl(a+n%%b,0)

Attempt This Online!

Julia 1.0, 16 bytes

~x=sum(x.%(1:x))

Try it online!

Go, 52 bytes

func(n int)(o int){for k:=1;k<=n;k++{o+=n%k};return}

Attempt This Online!

K (ngn/k), 16 bytes (Non-competitive)

{+/{x!g}'1+!g-1}

Try it online!

Non-competitive, because required the use of a global variable called g to get input. The reason is because lambda functions in K cannot access variables of another function if they are in that function.

Explanation:

{+/{x!g}'1+!g-1}    Main function. Takes g as input (g=14)
           !        Generate a range from 0 to
            g-1     g - 1 (exclusive)               (g-1=13=>range=0..12)
         1+         + 1 for each element            (range=1..13)
        '           For each element
   {   }            Execute a function that returns
    x!g             g mod x (x = element)
 +/                 Sum

Rust, 27 characters

|n|(1..n).map(|i|n%i).sum()

Based on Should rust anonymous functions fully specify parameter types? I assume that return type inference is also fine.

Try it online!

J-uby, 24 bytes

Equivalent to my Ruby answer.

(:-&(:& &:%|:+&:sum))%:+

Attempt This Online!

PowerShell Core, 37 30 bytes

param($a)1..$a|%{$r+=$a%$_}
$r

Try it online!

-7 bytes thanks to @mazzy!

Ly, 15 13 bytes

ns,[:lf%f,]&+

Try it online!

Thanks LyricLy for the tip that dropped 2 chars.

This generates the modulo numbers on a stack, then sums them and relies on the default action to print the stack to show the answer.

ns,             # Read the N req from STDIN, stash it away, then decrement
    [     ,]    # Loop to decrement the top of stack and exit then that's 0
     :l         # Duplicate the top of stack, restore N from backup cell
       f%f      # Flip top two stack enrtries, do modulo math, flip again
             &+ # Sum the stack
                # Ends with one entry on the stack, which prints as a number

Knight, 30 bytes

;=x+=s=y 0P;W>x=y+yT=s+s%x yOs

Try it online!

Pretty straightforward.

# init x with input converted to number,
# and sum and y to 0
; = x + (= sum = y 0) PROMPT
# for 1..x
; WHILE (> x (= y + y 1))
    # sum += x % y
    : = sum + s (% x y)
: OUTPUT sum

Factor + math.unicode, 33 bytes

[ dup [1,b) [ mod ] with map Σ ]

Try it online!

Vyxal, 3 bytes

ɽ%∑

Try it Online!

Vyxal s, 2 bytes

ɽ%

Try it Online!

MMIX, 32 bytes (8 instrs)

00000000: c1020000 e3010000 1cff0002 25020201  Ḋ£¡¡ẉ¢¡¡÷”¡£%££¢
00000010: feff0006 200101ff 5b02fffc f8020000  “”¡© ¢¢”[£”‘ẏ£¡¡
modsum  SET  $2,$0              // i = n
        SET  $1,0               // s = 0
0H      DIV  $255,$0,$2
        SUB  $2,$2,1
        GET  $255,rR
        ADD  $1,$1,$255         // loop: s += n % i--
        PBNZ $2,0B              // if(i) goto loop
        POP  2,0                // return [s,n]

Labyrinth, 38 bytes

?_"):}}:{%={
@ ;        {
!{{=-{:}}:}+

Try it online!

Slight improvement to existing answer.

How it works

Stack notation is a b ... c | d e ... f where a b ... c part is the main stack, d e ... f is auxiliary, and c and d are the top of two stacks. I found this notation useful in developing and explaining the answer.

        Start at the top left
?_"     Push input and a 0, going straight through the junction
        n i=0 | sum=0
)       Increment i
:}}     n | i i sum
:{%=    n i | n%i sum
{{+}    n i | sum'=sum+n%i
:}}:{-  n n-i | i sum'
={      n i n-i | sum'
;       If n-i is nonzero, turn right and discard n-i, continuing the loop
{!@     Otherwise go straight, print sum and terminate

Ruby, 23 bytes

->n{eval [*0..n]*"+n%"}

Try it online!

Evaluates a string like 0+n%1+n%2+n%3+n%4+n%5 for n=5.

Brachylog, 9 bytes

⟨gz⟦₆⟩%ᵐ+

Try it online!

Ahead, 21 bytes

I&l@O+K<
~>td-! ntd%~

Try it online!

F#, 35 bytes

let s v=Seq.sumBy(fun x->v%x){1..v}

Try it online!

Pretty straight-forward.

dc, 31 bytes

[dz%rdz<B]sBd1<B0*0[+z1<C]dsCxp

Try it online!

Assume our input is the only value on the stack. Macro B duplicates top of stack, calculates stack depth, and performs modulo. Runs until stack depth is equal to the input. This works for numbers greater than 1, so we don't run B automatically, but instead only if it's greater than 1 (d1<B). B leaves the input value on top-of-stack, so we multiply by 0. Since 0 is the desired result for an input of 1, this is fine for 1 as well. However, 1 doesn't leave us enough items on the stack to do the initial summation in macro C, so we put another 0 on the stack just in case. Macro C simply adds the two values on top of the stack, and keeps going until the stack only has a single value. Finally, we print.

Japt -mx, 3 bytes

N%U

Try it online!

Forth (gforth), 35 bytes

: f 0 over 1 do over i mod + loop ;

Try it online!

Explanation

Loops over all numbers from 1 to n-1 and adds n%i to the sum

Code Explanation

: f            \ start a new word definition
  0 over       \ add a 0 to the stack and place a copy of n above it
  1 do         \ start a counted loop from 1 to n-1
    over i     \ copy n to the the top of the stack and place the loop index above it
    mod +      \ take n%i and add it to the sum
  loop         \ end the counted loop
;              \ end the word definition
  

PHP, 61 bytes

-2 bytes for removing the closing tag

<?php $z=fgets(STDIN);for($y=1;$y<$z;$y++){$x+=$z%$y;}echo$x;

Try it online!

Ruby, 28 27 23 bytes

-4 bytes thanks to @daniero.

->n{(1..n).sum{|i|n%i}}

Try it online!

Ruby, 28 bytes

f=->n{n>($.+=1)?n%$.+f[n]:0}

Try it online!

SNOBOL4 (CSNOBOL4), 69 68 bytes

	N =INPUT
A	I =I + 1
	S =LT(I,N) S + REMDR(N,I)	:S(A)
	OUTPUT =S
END

Try it online!

	N =INPUT				;* read in input
A	I =I + 1				;* I is initialized to 0 so this increments it to 1
	S =LT(I,N) S + REMDR(N,I)	 :S(A)	;* similarly with S, add to the remainder
	LT(I,N) :S(A)				;* on success (I < N), goto A
	OUTPUT =S				;* output the sum
END						;* terminate the program

Python 2, 44 bytes

lambda n:sum(map(lambda x:x%(n-x),range(n)))

Try it online!

EDIT: Changed range(0,n) to range(n)

T-SQL, 80 79 bytes

-1 byte thanks to @MickyT

WITH c AS(SELECT @ i UNION ALL SELECT i-1FROM c WHERE i>1)SELECT SUM(@%i)FROM c

Receives input from an integer parameter named @, something like this:

DECLARE @ int = 14;

Uses a Common Table Expression to generate numbers from 1 to n. Then uses that cte to sum up the moduluses.

Note: a cte needs a ; between the previous statement and the cte. Most code I've seen puts the ; right before the declaration, but in this case I can save a byte by having it in the input statement (since technically my code by itself is the only statement).

Try it (SEDE)


The less "SQL-y" way is only 76 bytes. This time the input variable is @i instead of @ (saves one byte). This one just does a while loop.

DECLARE @ int=2,@o int=0WHILE @<@i BEGIN SELECT @o+=@i%@,@+=1 END PRINT @o

Pushy, 13 bytes

&1{:2d%vh;OS#

Try it online!

&1{                 \ Make the stack [n, 1, n]
   :     ;          \ n times do (this consumes last n):
    2d              \    Copy the last two items
      %v            \    Get remainder and put result on stack
        h           \    Increment divisor
          OS        \ Sum the second stack
            #       \ Output the result

Befunge-93, 36 bytes

p&:10p1>-#1:_$v_g.@
 :p00+g00%\g01<^

Try It Online

Common Lisp, 50 47 bytes

(lambda(n)(loop as i from 1 to n sum(mod n i)))

Try it online!

Clean, 39 bytes

Literally just Bruce Forte's Haskell answer, but in Clean.

import StdEnv
@x=sum(map((rem)x)[1..x])

Try it online!

Brain-Flak, 70 62 bytes

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

Try it online!

It turns out that the straightforward approach is better. Also, keeping a copy of n on the third stack instead of the first stack saves bytes.

(([{}])<>)                                                      Initialize both stacks with -n
           {                                              }{}   For all k from n down to 1:
             <>(({})<                      >)                   Store -n on third stack
                     <>{(({})){({}())<>}{}}                     Main part of standard modulus program
                                                                (except that the arguments are negative)
                                             <>
            <                                  >                Ignore evaluation of -n
                                                {}[({}())]      Recover n mod k, and decrement k for the next iteration
          (                                                  )  Sum over all iterations and push

J, 14 Bytes

M=:+/@:|~}.@i.

How it works:

M=:                 | Define the verb M
            i.      | Get integers in the range [0, input)
         }.@        | Remove the leading 0
       |~           | Take the original input mod each of these integers, making a new array
   +/@:             | Sum this array

Example:

    M 14
31
    M"0 >:i.20    NB. Apply M to each of the integers from 1-20 inclusive
0 0 1 1 4 3 8 8 12 13 22 17 28 31 36 36 51 47 64 61

Windows Batch (CMD), 63 bytes

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

Previous 64-byte version:

@set/ai=%2+1,s=%3+%1%%i
@if %i% neq %1 %0 %1 %i% %s%
@echo %s%

Labyrinth - 45 Characters

?:}}""):={%={{+
     ;        "
@!{{{-{=:}}}::}

Basically, it sets up by taking the input of the number that we are modulo summing. It then starts at one, takes the modulo of that number, and checks if it has reached the target number yet. If it hasn't, take the modulo again and add it to the previous one.

(I left out a lot of stack manipulations if you hadn't guessed, and yes, it actually does output the sum of the modulus up to that number)

Perl 6, 21 16 bytes

{sum $_ «%«(1..$_)}

{sum $_ X%1..$_}

Try it online!

-5 bytes (!) thanks to Brad Gilbert.

Funky, 25 bytes

n=>fors=~-i=1i<n)s+=n%i++

Just the Naïve answer, seems to work.

Try it online!

Desmos, 25 bytes.

f(x)=\sum_{n=1}^xmod(x,n)

Paste into Desmos, then run it by calling f.

When pasted into Desmos, the latex looks like this

The graph however looks like

Although it looks random and all over the place, that's the result of only supporting integers.

RProgN 2, 9 bytes

x=x³x\%S+

Explained

x=x³x\%S+
x=          # Store the input in "x"
  x         # Push the input to the stack.
   ³x\%     # Define a function which gets n%x
       S    # Create a stack from "x" with the previous function. Thus this gets the range from (1,x), and runs (i%x) on each element.
        +   # Get the sum of this stack.

Try it online!

ReRegex, 71 bytes

#import math
(_*)_a$/d<$1_>b$1a/(\d+)b/((?#input)%$1)+/\+a//u<#input
>a

Try it online!

ARBLE, 19 bytes

sum(range(1,a)|a%i)

Try it online!

MaybeLater, 56 bytes

whenf is*{n=0whenx is*{ifx>0{n=n+f%x x--}elseprintn}x=f}

Try it online!

Clojure, 38 bytes

#(apply +(for[i(range 1 %)](mod % i)))

Well this is boring, I was hoping #(apply +(map mod(repeat %)(range 1 %))) would have been shorter as mod gets rarely used in map context.

4, 67 bytes

4 doesn't have any modulo built in.

3.79960101002029980200300023049903204040310499040989804102020195984

Try it online!

Japt, 6 5 bytes

Saved 1 byte thanks to @Shaggy

Æ%XÃx

Test it online!

How it works

         Implicit: U = input number
Æ        Create the range [0, U),
 %XÃ       mapping each item X to U%X. U%0 gives NaN.
    x    Sum, ignoring non-numbers.
         Implicit: output result of last expression

J, 9 bytes

-~1#.i.|]

How it works

        ] - the argument 
       |  - mod   
     i.   - list from 0 to argument - 1
  1#.     - sum (base 1 conversion)
-~        - subtract the argument (to get rid of the n mod 0)  

Try it online!

Gaia, 8 bytes

@:…)¦%¦Σ

Try it online!

MATLAB, 19 bytes

@(n)sum(mod(n,1:n))

Very straightforward, mod calculates n%x for each natural number below n. and sum just sums them all. Test:

@(n)sum(mod(n,1:n))
ans(14)
ans = 

    @(n)sum(mod(n,1:n))
ans =
    31.0000e+000

Add++, 14 bytes

L,RAdx$p@BcB%s

Try it online!

How it works

L,   - Create a lambda function.
     - Example argument:     [7]
  R  - Range;        STACK = [[1 2 3 4 5 6 7]]
  A  - Argument;     STACK = [[1 2 3 4 5 6 7] 7]
  d  - Duplicate;    STACK = [[1 2 3 4 5 6 7] 7 7]
  x  - Repeat;       STACK = [[1 2 3 4 5 6 7] 7 [7 7 7 7 7 7 7]]
  $p - Swap and pop; STACK = [[1 2 3 4 5 6 7] [7 7 7 7 7 7 7]]
  @  - Reverse;      STACK = [[7 7 7 7 7 7 7] [1 2 3 4 5 6 7]]
  Bc - Zip;          STACK = [[7 1] [7 2] [7 3] [7 4] [7 5] [7 6] [7 7]]
  B% - Modulo each;  STACK = [0, 1, 1, 3, 2, 1, 0]
  s  - Sum;          STACK = [8]

Julia 0.4, 15 bytes

x->sum(x%[1:x])

Try it online!

Pari/GP, 17 bytes

n->sum(m=1,n,n%m)

Try it online!

APL (Dyalog), 5 bytes

+/⍳|⊢

Try it online!

How?

Monadic train -

+/ - sum

- n

| - vectorized modulo

- the range of n

APL+WIN, 10 bytes

+/(⍳n)|n←⎕

Prompts for screen input.

Mathematica, 18 bytes

#~Mod~i~Sum~{i,#}&

Try it online!

Java (OpenJDK 8), 45 bytes

n->{int m=n,s=0;for(;m-->1;)s+=n%m;return s;}

Try it online!

Neim, 3 bytes

Try It Online!

𝐈𝕄𝐬

Explanation:

𝐈      # Inclusive range
 𝕄    # Modulo each element with input
   𝐬   # Sum the list

Ruby, 23 bytes

->n{(1..n).sum{|i|n%i}}

Try it online!

Pip, 7 bytes

$+a%\,a

Try it online!

         a is 1st cmdline arg
    \,a  Inclusive range from 1 through a
  a%     Take a mod each of those numbers (a%a is 0, so doesn't affect the sum)
$+       Fold on +
         Output (implicit)

R, 20 bytes

sum((n=scan())%%1:n)

Try it online!

Standard ML (MLton), 53 51 bytes

fn& =>let fun f 1a=a|f%a=f(% -1)(a+ &mod%)in f&0end

Try it online!

Ungolfed:

fn n =>
   let fun f 1 a = a
         | f x a = f (x-1) (a + n mod x)
   in  
       f n 0
   end

Previous 53 byte version:

fn n=>foldl op+0(List.tabulate(n-1,fn i=>n mod(i+1)))

Try it online!

Explanation:

List.tabulate takes an integer x and a function f and generates the list [f 0, f 1, ..., f(x-1)]. Given some number n, we call List.tabulate with n-1 and the function fn i=>n mod(i+1) to avoid dividing by zero. The resulting list is summed with foldl op+0.

MATL, 4 bytes

t:\s

Try it online!

Explanation:

t      % Duplicate input. Stack: {n, n}
 :     % Range 1...n. Stack: {n, [1...n]}
  \    % Modulo. Stack: {[0,0,2,2,4,...]}
   s   % Sum. Implicitly display result.

Ohm v2, 4 bytes

D@%Σ

Try it online!

Charcoal, 9 bytes

IΣEN﹪Iθ⊕ι

Try it online!

Link is to the verbose version of the code:

Print(Cast(Sum(Map(InputNumber(),Modulo(Cast(q),++(i))))));

05AB1E, 3 bytes

L%O

Try it online!

Pyth, 5 bytes

s%LQS

s%LQS - Full program, inputs N from stdin and prints sum to stdout
s     - output the sum of
 %LQ  - the function (elem % N) mapped over 
    S - the inclusive range from 1..N

Try it online!

Haskell, 22 bytes

f x=sum$mod x<$>[1..x]

Try it online!

Explanation

Yes.

Perl 5, 23 + 1 (-p) = 24 bytes

//;map$\+=$'%$_,1..$_}{

Try it online!

05AB1E, 6 bytes

ÎGIN%+

Try it online!

My first 05AB1E program ;)

Btw I got two 39s, 1 for JS6 and 1 for python, but I was too late

Explanation:

ÎGIN%+
Î                      # Push 0, then input, stack = [(accumulator = 0), I]
 G                     # For N in range(1, I), stack = [(accumulator)]
  IN                   # Push input, then N, stack = [(accumulator), I, N]
    %                  # Calculate I % N, stack = [(accumulator), I % N]
     +                 # Add the result of modulus to accumulator

Husk, 5 bytes

ΣṠM%ḣ

Try it online!

Explanation

ΣṠM%ḣ  -- implicit input x, example: 5
 ṠM%   -- map (mod x) over the following..
    ḣ  -- ..the range [1..x]: [5%1,5%2,5%3,5%4,5%5] == [0,1,2,1,0]
Σ      -- sum: 0+1+2+1+0 == 4

Python 3, 37 bytes

lambda a:sum(a%k for k in range(1,a))

Try it online!

JavaScript (ES6), 26 bytes

f=(n,k=n)=>n&&k%n+f(n-1,k)

Demo

f=(n,k=n)=>n&&k%n+f(n-1,k)

for(n = 1; n < 30; n++) {
  console.log('a(' + n + ') = ' + f(n))
}

C, 43 bytes

s,m;f(n){for(s=m=0;m++<n;s+=n%m);return s;}

Try it online!

C (gcc), 38 bytes

s,m;f(n){for(s=m=0;m++<n;s+=n%m);s=s;}

Try it online!

Jelly, 3 bytes

%RS

Explanation

%RS
 R   Range(input)  [1...n]
%    Input (implicit) modulo [1...n]->[n%1,n%2...n%n]
  S  Sum of the above

Try it online!