[Question]
  [
I call this sequence "the Jesus sequence", because it is the *sum of mod*.</pun>
For this sequence, you take all the positive integers *m* less than the input *n*, and take the sum of *n* modulo each *m*. In other words:
$$a\_n = \sum\_{m=1}^{n-1}{n\bmod m}$$
For example, take the term *14*:
```
14 % 1 = 0
14 % 2 = 0
14 % 3 = 2
14 % 4 = 2
14 % 5 = 4
14 % 6 = 2
14 % 7 = 0
14 % 8 = 6
14 % 9 = 5
14 % 10 = 4
14 % 11 = 3
14 % 12 = 2
14 % 13 = 1
0+0+2+2+4+2+0+6+5+4+3+2+1=31
```
Your goal here is to write a function that implements this sequence. You should take the sequence term (this will be a positive integer from 1 to 231) as the only input, and output the value of that term. This is [OEIS A004125](https://oeis.org/A004125).
As always, [standard loopholes](https://codegolf.meta.stackexchange.com/q/1061/62402) apply and the shortest answer in bytes wins!
  
[Answer]
# [Haskell](https://www.haskell.org/), 22 bytes
```
f x=sum$mod x<$>[1..x]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwra4NFclNz9FocJGxS7aUE@vIvZ/bmJmnoKtQnpqiXN@XklqXkmxgp2drUJBUWZeiYKeQhoQF6Umpvw3NAEA "Haskell – Try It Online")
### Explanation
Yes.
[Answer]
# [Funky](https://github.com/TehFlaminTaco/Funky), 25 bytes
```
n=>fors=~-i=1i<n)s+=n%i++
```
Just the Naïve answer, seems to work.
[Try it online!](https://tio.run/##SyvNy678n2b7P8/WLi2/qNi2TjfT1jDTJk@zWNs2TzVTW/t/QVFmXolGmoahiabmfwA "Funky – Try It Online")
# [Desmos](https://www.desmos.com/calculator), 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
![](https://a-ta.co/mathjax/%24!ZlxsZWZ0KHhccmlnaHQpPVxzdW1eeF97bj0xfVx0ZXh0e21vZH1cbGVmdCh4LG5ccmlnaHQp.svg)
The graph however looks like
![](https://i.gyazo.com/b46a90eaa3fddd3269387480cce10856.png)
Although it looks random and all over the place, that's the result of only supporting integers.
# [RProgN 2](https://github.com/TehFlaminTaco/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!](https://tio.run/##Kyooyk/P0zX6/7/CtuLQ5ooY1WDt////G5oAAA "RProgN 2 – Try It Online")
# [ReRegex](https://github.com/TehFlaminTaco/ReRegex), 71 bytes
```
#import math
(_*)_a$/d<$1_>b$1a/(\d+)b/((?#input)%$1)+/\+a//u<#input
>a
```
[Try it online!](https://tio.run/##K0otSk1Prfj/XzkztyC/qEQhN7Ekg0sjXkszPlFFP8VGxTDeLknFMFFfIyZFWzNJX0PDXjkzr6C0RFNVxVBTWz9GO1Ffv9QGIsZll/j/v6EJAA "ReRegex – Try It Online")
# [ARBLE](https://github.com/TehFlaminTaco/ARBLE), 19 bytes
```
sum(range(1,a)|a%i)
```
[Try it online!](https://tio.run/##SyxKykn9/7@4NFejKDEvPVXDUCdRsyZRNVPz////hiYA "ARBLE – Try It Online")
# [MaybeLater](https://github.com/TehFlaminTaco/MaybeLater), 56 bytes
```
whenf is*{n=0whenx is*{ifx>0{n=n+f%x x--}elseprintn}x=f}
```
[Try it online!](https://tio.run/##y02sTErNSSxJLfr/vzwjNS9NIbNYqzrP1gDEqQBzMtMq7AyAQnnaaaoVChW6urWpOcWpBUWZeSV5tRW2abX/0xRsFTSKUhNTEjV1Df4bmgAA "MaybeLater – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes
```
L%O
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fR9X//39DEwA "05AB1E – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~28~~ ~~27~~ 23 bytes
-4 bytes thanks to @daniero.
```
->n{(1..n).sum{|i|n%i}}
```
[Try it online!](https://tio.run/##KypNqvyflmf7X9cur1rDUE8vT1OvuDS3uiazJk81s7b2f4FCWl60oUnsfwA "Ruby – Try It Online")
## Ruby, 28 bytes
```
f=->n{n>($.+=1)?n%$.+f[n]:0}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6vOs9OQ0VP29ZQ0z5PFchIi86LtTKo/V@gkBZtaBL7HwA "Ruby – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/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!](https://tio.run/##y0rNyan8/181KPj///@GJgA "Jelly – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 4 bytes
```
t:\s
```
[Try it online!](https://tio.run/##y00syfn/v8Qqpvj/f0MTAA "MATL – 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.
```
[Answer]
# R, 20 bytes
```
sum((n=scan())%%1:n)
```
[Try it online!](https://tio.run/##K/r/v7g0V0Mjz7Y4OTFPQ1NTVdXQKk/zv6HJ//8A "R – Try It Online")
[Answer]
# [Ohm v2](https://github.com/nickbclifford/Ohm), 4 bytes
```
D@%Σ
```
[Try it online!](https://tio.run/##y8/INfr/38VB9dzi//8NTQA "Ohm v2 – Try It Online")
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 5 bytes
```
+/⍳|⊢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R2wRt/Ue9m2sedS0Ccg@tALKNDAA "APL (Dyalog Unicode) – Try It Online")
**How?**
Monadic train - 
`+/` - sum
`⊢` - `n`
`|` - vectorized modulo
`⍳` - the range of `n`
[Answer]
# [Python 2](https://docs.python.org/2/), 44 bytes
```
lambda n:sum(map(lambda x:x%(n-x),range(n)))
```
[Try it online!](https://tio.run/##LcgxCoAwDAXQ3VP8RUiggjoWvIlLRauCjaVWiKevg77xxSdvp/TFYxjL4cI0O4i97kDBRfpDrdYkjbJJTtaFhJmLPxMUu@C7rm3ZVgBi2iVDDTwplxc "Python 2 – Try It Online")
EDIT: Changed range(0,n) to range(n)
[Answer]
# Rust, 27 characters
```
|n|(1..n).map(|i|n%i).sum()
```
Based on [Should rust anonymous functions fully specify parameter types?](https://codegolf.meta.stackexchange.com/questions/25156/should-rust-anonymous-functions-fully-specify-parameter-types) I assume that return type inference is also fine.
[Try it online!](https://tio.run/##LctNCoMwEEDhtZ5iKhRmQALRrio9TJAUBpJR8rNKPHsaqOv3vZBjal8Bb1iQyjg4m2B3R8zBwgdalYpaKSHlzYmVqzyZVMweqQ3bnwcbs0tv4HXpyz2jflHvZ2BJTh44lWuab9rD1X4 "Rust – Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), 16 bytes
```
~x=sum(x.%(1:x))
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/v67Ctrg0V6NCT1XD0KpCU/N/dEFRZl5JTp5GTkFiikamjpGmjpKVgpIOmFuXqWOsqamQll@kkKmQmadgaGVoGvsfAA "Julia 1.0 – Try It Online")
[Answer]
# 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))
}
```
[Answer]
# [Python 3](https://docs.python.org/3/), 37 bytes
```
lambda a:sum(a%k for k in range(1,a))
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHRqrg0VyNRNVshLb9IIVshM0@hKDEvPVXDUCdRU/M/SDARSdDAQNOKSwEICooy80o00pSqE2utFKrTNBI1a5U0/wMA "Python 3 – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 9 bytes
```
ＩΣＥＮ﹪Ｉθ⊕ι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8M3sUDDM6@gtMSvNDcptUhDU8c3P6U0Jx@iolBTR1tbI1MTDKz//zc0@a9blgMA "Charcoal – Try It Online")
Link is to the verbose version of the code:
```
Print(Cast(Sum(Map(InputNumber(),Modulo(Cast(q),++(i))))));
```
[Answer]
# [Standard ML (MLton)](http://www.mlton.org/), ~~53~~ 51 bytes
```
fn& =>let fun f 1a=a|f%a=f(% -1)(a+ &mod%)in f&0end
```
[Try it online!](https://tio.run/##TYsxC8IwFIT3/oqjkJIglUbdJN2dXUUJNE8K6YuYp5P/vcYu9qbv7vjyFNspSuL57SPIzcQNXB@DgF4MgvXOf0h5R1qhtUb7DZopDcqM5W66wMOiSsgCh8dzZEGCJkZ2fb7WF65NGU4sW0lnKf@9VKp@0q0YukLJotvjn3cr3q/YHtal68z8BQ "Standard ML (MLton) – 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!](https://tio.run/##TYyxDgIhDIb3e4rmJsh5BtTNwG7i5mo0mDsMCZSLVF8f6y3S6fvb/2tJcUyRMtaPi@BN9QhorM9xipCXQYlzKLQl93hHR7PAUW@4EoxFSHkSYdBSylWmuRAYWF4BCTIIrhVjy62/Yi95cUL@ky/E9ydH3/2kOxuiA55V18c/7xreN6wPbVBK1i8 "Standard ML (MLton) – 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`.
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 45 bytes
```
n->{int m=n,s=0;for(;m-->1;)s+=n%m;return s;}
```
[Try it online!](https://tio.run/##bU49a8MwFNz9K46Awa4/SLsqNnTMEDqETqWD6o8g13oS0nPABP92V07bqR0eB3f37m6QV1kY29HQfq5KW@MYQ@DKidVYPojoD@fZdVL/K/UTNawMbaKdPkbVoBml9zhJRbhFwA/rWXKAq1EtdNCSMztFl7d3SHfx6d0KHIlfSbr5xXZOsnHoUa1U1DdFDF1R7qu96I1LhC6K@lGkPqso1sJ1PDmCF8sq7kGbZ/tRqLAXAQ542jDLfquA8@y506WZuLRhC/fJLm5R1IjbmHY5VI6@lNaO87MPwxKVpt/hS7Tdsn4B "Java (OpenJDK 8) – Try It Online")
[Answer]
# [Mathematica](https://www.wolfram.com/wolframscript/), 18 bytes
```
#~Mod~i~Sum~{i,#}&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7X7nONz@lLrMuuDS3rjpTR7lW7X9AUWZeSXRatKFJbOx/AA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~6~~ 5 bytes
*Saved 1 byte thanks to @Shaggy*
```
Æ%XÃx
```
[Test it online!](https://ethproductions.github.io/japt/?v=1.4.5&code=xiVYw3g=&input=MTQ=)
### 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
```
[Answer]
# [4](https://github.com/urielieli/py-four), 67 bytes
**4** doesn't have any *modulo* built in.
```
3.79960101002029980200300023049903204040310499040989804102020195984
```
[Try it online!](https://tio.run/##HYo5DoBADAP7fUVWtAg5BxAX/Juaj4WAprBHmqjy7SQPaAODkdkDR5sjSLghGtffAsxOQr8Yyp0ZVXOMRaZc4r7Kc/fRjBc "4 – Try It Online")
[Answer]
# 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)](https://data.stackexchange.com/codegolf/query/edit/770634)
---
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
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 3 bytes
```
ɽ%∑
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C9%BD%25%E2%88%91&inputs=14&header=&footer=)
# [Vyxal](https://github.com/Lyxal/Vyxal) `s`, 2 bytes
```
ɽ%
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=s&code=%C9%BD%25&inputs=14&header=&footer=)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
ÎGIN%+
```
[Try it online!](https://tio.run/##MzBNTDJM/f//cJ@7p5@q9v//ZkYA "05AB1E – 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
```
[Answer]
# [Pyth](https://github.com/isaacg1/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!](https://tio.run/##K6gsyfj/v1jVJzD4/39DEwA "Pyth – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 23 bytes
```
->n{(1..n).sum{|i|n%i}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsNQTy9PU6@4NLe6JrMmTzWztvY/SMzQRFMvN7GguqaipkAhLboitvY/AA "Ruby – Try It Online")
[Answer]
# Julia 0.4, 15 bytes
```
x->sum(x%[1:x])
```
[Try it online!](https://tio.run/##yyrNyUz8n2b7v0LXrrg0V6NCNdrQqiJW839BUWZeSU6eRpqGoYmm5n8A "Julia 0.4 – Try It Online")
[Answer]
# [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 14 bytes
```
L,RAdx$p@BcB%s
```
[Try it online!](https://tio.run/##S0xJKSj4/99HJ8gxpUKlwMEp2Um1@P///4YmAA "Add++ – 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]
```
[Answer]
## 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%
```
[Answer]
# [PHP](https://php.net/), 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!](https://tio.run/##K8go@P/fxr4go0BBpco2LT21pFgjOMTF00/TOi2/SEOl0tbQWqXSRqUKSGpra1arVGjbqlSpqlRa16YmZ@SrVFj//29oAgA "PHP – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) `-mx`, 3 bytes
```
N%U
```
[Try it online!](https://tio.run/##y0osKPn/30819P9/QxMF3dwKAA "Japt – Try It Online")
]