Problem:


Score : 400 points

Problem Statement

For a positive integer X, let f(X) be the number of positive divisors of X.

Given a positive integer N, find \sum_{K=1}^N K\times f(K).

Constraints

1 \leq N \leq 10^7

Input

Input is given from Standard Input in the following format:

N

Output

Print the value \sum_{K=1}^N K\times f(K).

Sample Input 1

4

Sample Output 1

23

We have f(1)=1, f(2)=2, f(3)=2, and f(4)=3, so the answer is 1\times 1 + 2\times 2 + 3\times 2 + 4\times 3 =23.

Sample Input 2

100

Sample Output 2

26879

Sample Input 3

10000000

Sample Output 3

838627288460105

Watch out for overflows.



Sample input:
4


Sample output:
23

Submission status: Accepted

Solution code:

def main2():
    n = int(input())
    res=0
    div = [0]*(n+1)
    for i in range(1,(n+1)):
        for j in range(0,n,i):
            if(i+j<=n):
                div[i+j]+=1
        res+=i*div[i]
    print(res)



if __name__ == '__main__':
    main2()

Submission status: Accepted

Solution code:
n=int(input())
print(n+sum(n//i*(n-n%i+i)>>1for i in range(1,n)))

Submission status: Accepted

Solution code:
n=int(input())
print(n+sum(n//i*(i+n-n%i)//2for i in range(1,n)))

Submission status: Accepted

Solution code:
n = int(input())
FK = [2] * (n+1)
FK[0] = 0
FK[1] = 1

if n == 1:
    print(1)
elif n == 2:
    print(5)
else:
    FK[2] = 2
    for i in range(4, n+1, 2):
        FK[i] += 1

    for i in range(3, n+1):
        for j in range(i*2, n+1, i):
            FK[j] += 1

    ans = 0
    for i in range(1, n+1):
        ans += i*FK[i]
        
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1, N + 1):
    ans += (N // i) * (N // i + 1) // 2 * i
print(ans)

Submission status: Accepted

Solution code:
def func(x, n):
    y = n//x
    return y*(y+1)*x//2

def resolve():
    N = int(input())
    res = 0

    for i in range(1, N + 1):
        res += func(i, N)

    print(res)

resolve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())

    ans = 0
    for i in range(1, n + 1):
        d = n // i
        ans += (i + (i * d)) * d // 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))


INF = float("inf")
MOD = 10**9 + 7

def main():
    n = INT()
    table = [0] * (n + 1)
    table[0] = 0
    table[1] = 1

    for i in range(2, n + 1):
        if table[i] == 0:
            table[i] = 2
            for j in range(i + i, n + 1, i):
                cnt = 0
                c = j
                while c % i == 0:
                    c //= i
                    cnt += 1
                table[j] = table[c] * (cnt + 1)

    # print(table)
    ans = 0
    for i in range(n + 1):
        ans += i * table[i]
    print(ans)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,math

N = int(sys.stdin.readline())
#counting prime
isPrime = [True]*(N+1)
f = [1]*(N+1)

for i in range(2,N+1):
    f[i] += 1
    j = i + i
    while j <= N:
        f[j] += 1
        j += i

sum = 0
for i in range(1,N+1):
    f[i] = f[i]*i
    sum += f[i]

print(sum)

Submission status: Accepted

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    d = [2] * (N+1)
    d[1] = 1
    for i in range(2,int(math.sqrt(N))+1):
        d[i*i] += 1
        j = i + 1
        while i * j <= N:
            d[i*j] += 2
            j += 1

    ans = 0
    for i in range(1,N+1):
        ans += i * d[i]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    def f(x):
        return x * (x + 1) // 2

    ans = 0
    for d in range(1, N + 1):
        m = N // d
        ans += d * f(m)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from math import isqrt
    # Return the integer part of the square root of the input.

    N = int(input())

    def f(x):
        return x * (x + 1) // 2

    ans = 0
    for k in range(1, isqrt(N) + 1):
        # https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2020-06-27abc-172
        # a*b<=N
        # k=min(a,b)
        # k*k, k*(k+1),...,k*m
        # k*jはkの倍数かつjの倍数なので,2回計上される
        # k*kはkの倍数として1回だけ計上されるので,2回分計上して過剰分を減らす
        m = N // k
        ans += 2 * k * (f(m) - f(k - 1)) - k * k
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
#sum[k:1 to N]floor(N/K)
ans=0
j=1
while(j*(j*1)<=N):
    b=1+(N//j)
    a=1+(N//(j+1))
    tmp=((N//a)*((N//a)+1))//2
    tmpa=(a*(a-1))//2
    tmpb=(b*(b-1))//2
    ans+=(tmpb-tmpa)*tmp
    j+=1
for i in range(1,a):
    ans+=i*((N//i)*((N//i)+1))//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

result = 0
for i in range(1,(n // 2 + 1)):
    terms = n // i
    result += terms * (terms * i + i) // 2

terms = n - n // 2
result += terms * (n // 2 + 1 + n) // 2

print(result)

Submission status: Accepted

Solution code:
N = int(input())

ans= 0

for i in range(1, N+1):
    q = N//i
    ans += q*(q*i+i) // 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

f = [1] * (n+1)
f[1] = 1

for i in range(2, n+1):
    for j in range(0,n+1,i):
        f[j] += 1
ans = 0
for k in range(1, n+1):
    ans += k * f[k]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

result = 0
for i in range(1,(n + 1)):
    terms = n // i
    result += terms * (terms * i + i) // 2

print(result)

Submission status: Accepted

Solution code:
import os
import sys


def solve(n):
    ans = 0
    for i in range(1, int(n ** 0.5) + 1):
        k = n // i
        ans += i * k * (k + 1) // 2
        if i != k:
            l = n // (i + 1)
            ans += i * (i + 1) * (k + l + 1) * (k - l) // 4
    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8,)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8,)', cache=True)(solve)

print(solve(int(input())))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(1, int(n ** 0.5) + 1):
    k = n // i
    ans += i * k * (k + 1) // 2
    if i != k:
        l = n // (i + 1)
        ans += i * (i + 1) * (k + l + 1) * (k - l) // 4
print(ans)

Submission status: Accepted

Solution code:
import sys, math,os
from io import BytesIO, IOBase
#data = BytesIO(os.read(0,os.fstat(0).st_size)).readline
# from bisect import bisect_left as bl, bisect_right as br, insort
# from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
# from decimal import Decimal
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
#sys.setrecursionlimit(100000 + 1)
INF = 10**9
mod = 998244353

n=int(data())
l=[1]*(n+1)
for i in range(1,n):
    for j in range(2*i,n+1,i):
        l[j]+=1
ans=0
for i in range(1,n+1):
    ans+=l[i]*i
out(ans)

Submission status: Accepted

Solution code:
import math
n=int(input())
ans=0
for i in range(1,n+1):
    k=n//i
    ans+=i*(k)*(k+1)//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = 0

for i in range(1, N+1):
  m = N//i
  ans += m*(m+1)*i//2

print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
N = int(input())

S = 0
def g(j):
    Y = N // j
    return Y * (Y + 1) * j // 2

print(sum([g(j) for j in range(1, N+1)]))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())

S = 0
def g(j):
    Y = N // j
    return Y * (Y + 1) * j // 2

print(sum([g(j) for j in range(1, N+1)]))

Submission status: Accepted

Solution code:
n = int(input())
res = 0
for i in range(1,n+1):
    res+=i*(1+n//i)*(n//i)//2
print(res)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()

ans = 0
for i in range(1, N+1):
	k = N//i
	ans += i * k*(k+1)//2

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=0
for i in range(1,n+1):
 a+=(i+(n//i)*i)*(n//i)//2
print(a)

Submission status: Accepted

Solution code:
import numpy as np
from numba import *

@njit('i8(i8,i8[:])', cache=True)
def solve(x,count):
    for i in range(2,x+1):
        for j in range(i,x+1,i):
            count[j] += 1
    return int(np.sum(np.arange(x+1)*count))

if __name__== "__main__":
    x = int(input())
    count = np.ones(x + 1, dtype=np.int64)
    print(solve(x,count))

Submission status: Accepted

Solution code:
N = int(input())
a = 0
for i in range (N):
	x= N//(i+1)
	a += x*(x+1)*(i+1)

a = a/2
	
print(int(a))

Submission status: Accepted

Solution code:
N = int(input())
rlt = 0
 
lst = [2]*(N+1)
lst[1] = 1
 
for i in range(2,N//2+1):
  j = 2
  while i*j <= N:
    lst[i*j] += 1
    j += 1

for i in range(1,N+1):
  rlt += i*lst[i]
  
print(rlt)

Submission status: Accepted

Solution code:
n = int(input())
print(sum(i * (n // i) * (n // i + 1) // 2 for i in range(1, n + 1)))

Submission status: Accepted

Solution code:
"""
AtCoder :: Beginner Contest 172 :: D :: Sum of Divisors
https://atcoder.jp/contests/abc172/tasks/abc172_d
"""
import sys

def summation(n):
    return (n * (n+1)) // 2

def solve(N):
    """Solve puzzle."""
    soln = 0
    for i in range(1, N+1):
        k = N // i
        soln += i * summation(k)
    return soln


def main():
    """Main program."""
    N = int(sys.stdin.readline())
    print(solve(N))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
cnt = [0]*(N+1)

for i in range(1, N+1):
    for j in range(i, N+1, i):
        cnt[j] += 1

ans = 0

for i in range(1, N+1):
    ans += i*cnt[i]

print(ans)

Submission status: Accepted

Solution code:
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque

input = sys.stdin.readline
#import numpy as n



def main():

    N = int(input())
    ans =0
    for i in range(1,N+1):
        num =  int(N/i)
        ans += int(num*(num+1)/2 *i)

    print(ans)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from functools import reduce
from operator import mul
from collections import defaultdict, Counter
from heapq import heappush, heappop
import sys
from math import sqrt, floor

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve(N):
    ret = 0
    i = 2
    while True:
        step = i // 2
        start = (i + 1) // 2 * step
        if start > N:
            break
        end = N // step * step
        ret += (start + end) * ((end - start) // step + 1) // 2
        i += 1
    print(ret)


def main():
    N = int(input())
    solve(N)


def _test():
    """
    >>> solve(4)
    23

    >>> solve(100)
    26879

    >>> solve(10000000)
    838627288460105
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()

Submission status: Accepted

Solution code:
n = int(input())
print(sum((i + (n // i * i)) * (n // i) // 2for i in range(1,n+1)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    n = int(input())
    ans = n * (n + 1) - 1  # 1とk 自信

    i = 2
    while i * i <= n:
        num = n // i
        min_i = i * i
        max_i = i * num
        ans += (num - i + 1) * (min_i + max_i)  # 自分自身
        ans -= min_i
        i += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# input

n = int(input())
ans = n * (n + 1) - 1  # 1とk 自信

i = 2
while i * i <= n:
    num = n // i
    min_i = i * i
    max_i = i * num
    ans += (num - i + 1) * (min_i + max_i)  # 自分自身
    ans -= min_i
    i += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = 0
for i in range(1, n+1):
    q = n//i
    s += q*(q*i+i) // 2
print(s)

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for j in range(1,N+1):
    ans += (j+j*(N//j))*(N//j)//2
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=0
for i in range(1,N+1):
  a+=(N//i)*(N//i+1)/2*i
print(int(a))

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(1,N+1):
    x=N//i
    y=i*x*(x+1)/2
    A.append(y)
print(int(sum(A)))

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
#======================================================#
def main():
    n = II()
    res = 0
    for i in range(1,n+1):
        y = n//i
        res += y*(y+1)*i//2
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for i in range(1, N+1):
    x = N//i
    ans += i*x*(x+1)//2

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
 
ans=0
for i in range(n):
  i=i+1
  a=i
  y=n//i
 
  ans+=(i*y*(y+1)/2)
 
 
 
print(int(ans))

Submission status: Accepted

Solution code:
import math
N = int(input())

ans = 0
for i in range(1,N+1):
    K = int(N/i)
    anstemp = i * K * (K+1) // 2
    ans += anstemp
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
c=0
ans=0
for i in range(1,n+1):
    c=n//i
    ans+=(c)*(c+1)*(i)//2
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from functools import reduce
from operator import mul
from collections import defaultdict, Counter
from heapq import heappush, heappop
import sys
from math import sqrt, floor

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve(N):
    ret = 0
    for i in range(1, N + 1):
        num = N // i
        end = num * i
        ret += (i + end) * num // 2
    print(ret)


def main():
    N = int(input())
    solve(N)


def _test():
    """
    >>> solve(4)
    23

    >>> solve(100)
    26879

    >>> solve(10000000)
    838627288460105
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()

Submission status: Accepted

Solution code:
soe = [0]*(10**7+1)
soe[1] = 1
for i in range(2,10**7+1):
    if soe[i]==0:
        for j in range(i,10**7+1,i):
            if soe[j]==0:
                soe[j]=i
n = int(input())
res = 0
for i in range(1,n+1):
    t = i
    d = dict()
    ans = 1
    
    while soe[t]!=t:
        d[soe[t]]=d.get(soe[t],0)+1
        t//=soe[t]
    if t!=1:
        d[soe[t]]=d.get(soe[t],0)+1
    for j in d:
        ans*=(d[j]+1)
    
    res+=ans*i

print(res)

Submission status: Accepted

Solution code:
import sys

from numba import njit

input = sys.stdin.readline


@njit
def make_n_divisor_table(n):
    table = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    return table


def main():
    N = int(input())

    table = make_n_divisor_table(N)

    ans = 0
    for i, v in enumerate(table):
        ans += i * v

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for j in range(1, N+1):
  Y = int(N / j)
  ans += (j * Y*(Y+1)/2)
print(int(ans))

Submission status: Accepted

Solution code:
import math
def main():

    N = int(input())

    d = [2 for _ in range(N+1)]
    d[1] = 1

    v = int(math.sqrt(N))

    for i in range(2, v+1):
        u = i
        for j in range(2, N//i+1):
            u += i
            d[u] += 1 + (j > v)

    ans = 0
    for i in range(1, N+1):
        ans += i * d[i]
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
'''
- f(X)のイメージ

x軸: 正整数, y軸: 約数

                    10 ... every 10
                  9    ... every 9
                8      ... every 8
              7        ... every 7
            6          ... every 6
          5          5 ... every 5
        4       4      ... every 4
      3     3     3    ... every 3
    2   2   2   2    2 ... every 2
  1 1 1 1 1 1 1 1 1  1 ... every 1

問題は Σ^N_{K=1} K × f(K) なので
約数の数f(K)にKが掛かっている。

なので上のイメージを少し変更して

                    10 ... Σ^floor(N/10)_{K=1} 10*K
                  9    ...
                8      ...
              7        ...
            6          ...
          5         10 ...
        4       8      ...
      3     6     9    ...
    2   4   6   8   10 ... Σ^floor(N/2)_{K=1} 2*K
  1 2 3 4 5 6 7 8 9 10 ... Σ^floor(N/1)_{K=1} 1*K

これの総和を求めれば良い。

=> Σ^N_{K=1} Σ^{floor(N/K)}_{L=1} K*L
'''
N = int(input())

# ans = 0
# for i in range(1, N+1):
#     for j in range(1, N//i+1):
#         ans += i*j

ans = 0
for i in range(1, N+1):
    ans += (i + N//i*i) * (N//i) // 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(1, n + 1):
    p = n // i
    ans += p * (p + 1) * i // 2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0

for i in range(1, n + 1):
    ans += (n // i) * (n // i + 1) * i // 2

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1, N + 1):
    n = N // i
    cnt = (n * (2 * i + (n - 1) * i)) // 2
    ans += cnt
print(ans)

Submission status: Accepted

Solution code:
# D - Sum of Divisors
from numba import njit


@njit
def solve(N):
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    return res


def main():
    N = int(input())
    print(solve(N))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
ans = [0] * (n+1)
for i in range(1,n+1):
    for j in range(1,n+1):
        if i*j > n: break
        ans[i*j] += 1
res = 0
for i in range(1,n+1):
    res += i*ans[i]
print(res)

Submission status: Accepted

Solution code:
import math
def main():

    N = int(input())

    d = [2 for _ in range(N+1)]
    d[1] = 1

    v = int(math.sqrt(N))
    for i in range(2, N//2+1):
        for j in range(i+i, N+1, i):
            d[j] += 1

    # v = int(math.sqrt(N))
    # for i in range(2, v+1):
    #     for j in range(i+i, N+1, i):
    #         d[j] += 1
    #         if j//i > v: d[j] += 1

    ans = 0
    for i in range(1, N+1):
        ans += i * d[i]
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
n=int(input())
ans = 0
for i in range(1, n+1):
    ans += (n//i) * ((n//i)+1)//2*i;
print(ans)

Submission status: Accepted

Solution code:
import math
def main():

    N = int(input())

    d = [2 for _ in range(N+1)]
    d[1] = 1

    # v = int(math.sqrt(N))
    for i in range(2, N//2+1):
        for j in range(i+i, N+1, i):
            d[j] += 1
            # if j//i > v: d[j] += 1

    ans = 0
    for i in range(1, N+1):
        ans += i * d[i]
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
def main():

    N = int(input())

    d = [2 for _ in range(N+1)]
    d[1] = 1

    # v = int(math.sqrt(N))
    for i in range(2, N//2+1):
        for j in range(i+i, N+1, i):
            d[j] += 1
            # if j//i > v: d[j] += 1

    ans = 0
    for i in range(1, N+1):
        ans += i * d[i]
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N = II()
res = 0
for i in range(1, N+1):
    n = N//i
    res += i*n*(n+1)//2

print(res)

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8


@njit(i8(i8))
def sum_g(N):
    res = 0
    for i in range(1,N+1):
        end = N // i
        res += end * (end + 1) * i // 2
    return res


def main():
    N = int(input())

    res = sum_g(N)

    print(res)


main()

Submission status: Accepted

Solution code:
n=int(input())

result = 0
for i in range(1,n+1):
  for j in range(i,n+1,i):
    result += j

print(result)

Submission status: Accepted

Solution code:
n = int(input())
print(sum([i * (n // i) * (n // i + 1) // 2 for i in range(1, n + 1)]))

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit


@njit
def sum_g(N):
    res = 0
    for i in range(1,N+1):
        end = N // i
        res += end * (end + 1) * i // 2
    return res


def main():
    N = int(input())

    res = sum_g(N)

    print(res) 


main()

Submission status: Accepted

Solution code:
n=int(input())

a=[0]*(n+1)
for i in range(1,n+1):
  for j in range(i,n+1,i):
    a[j] += 1

result = 0
for i in range(n+1):
  result += i*a[i]
print(result)

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())

    res = 0

    for i in range(1,N+1):
        end = N // i
        res += end * (end + 1) * i // 2

    print(res) 




main()

Submission status: Accepted

Solution code:
N = int(input())

summation = 0
for j in range(1, N+1):
    Y = N//j
    #print(j, Y, Y*(1+Y)*j/2)
    summation += Y*(1+Y)*j/2

print(int(summation))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())

sum = 0
for k in range(1, N+1):
    for i in range(k, N+1, k):
        sum += i

print(sum)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().strip())

ans = 0
for i in range(1, N+1):
    for j in range(i, N+1, i):
        ans += j

print(ans)

Submission status: Accepted

Solution code:
N=int(input())

ans=0
for i in range(1, N+1):
    j = N // i
    ans += i* (j+1)*j // 2

print(ans)

Submission status: Accepted

Solution code:

N = int(input())

factors = [0] * (N + 1)

for i in range(2, N + 1):
	if factors[i] == 0:
		for j in range(i, N + 1, i):
			factors[j] = i

total = 1

for i in range(2, N + 1):
	table = {}
	j = i
	while j > 1:
		f = factors[j]
		if f in table:
			table[f] += 1
		else:
			table[f] = 1
		
		j //= f
	count = 1
	for c in table.values():
		count *= (c + 1)
	total += i * count

print(total)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().strip())

ans = 0
for i in range(1, N+1):
    j = N // i
    ans += j * (j+1) * i // 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = n * (n + 1) // 2

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        ans += j

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

res = 0
for i in range(1, N + 1):
  y = N // i
  res += ((1 + y) * y * i) // 2

print(res)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
for i in range(1, n + 1):
  k = n // i
  ans += i * k * (k + 1) // 2
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n = int(input())
ans = 0
for i in range(1, n+1):
    v = (n)//i
    ans += i*(v+1)*v//2
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()

    ans = 0
    sqrt = int(N ** 0.5)

    for m in range(1, sqrt + 1):
        b = N//m
        ans += m * (m + b) * (b + 1 - m)
    ans -= sqrt * (sqrt + 1) * (2 * sqrt + 1) // 6
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        target = i
        current = 1
        while True:
            target = i * current
            current += 1
            if target > N:
                break
            ans += target
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = N * (N + 1) // 2
ans = 2 * ans - 1
if N == 1:
    print(ans)
    exit()
for i in range(2, N // 2 + 1):
    M = N - (N % i)
    ans += (i + M) * (M // i) // 2
    ans -= i
print(ans)

Submission status: Accepted

Solution code:
def c(x):
    return x * (x + 1) // 2


n = int(input())
ans = 0
for i in range(1, n + 1):
    ans += i * c(n // i)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans=0
lastk=n
for i in range(1,n+1):
    k=n//i
    ans+=i*(i-1)//2*(lastk+k+1)*(lastk-k)//2
    if i>k:
        break
    ans+=k*(k+1)//2*i
    if i==k:
        break
    lastk=k

print(ans)

Submission status: Accepted

Solution code:
from numba import jit, i8, void


def g(n):
    return n * (n + 1) // 2


@jit(i8(i8))
def solve(n):
    ans = 0
    for i in range(1, n + 1):
        ans += i * g(n // i)
    return ans

def main():
    print(solve(int(input())))


main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    return N,


@njit
def solve(N):
    ndivs = 0
    for i in range(1, N+1):
        for j in range(i, N+1, i):
            ndivs += j
    return ndivs


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
n=int(input())
ans=0
for i in range(1,n+1):
    m=n//i
    ans+=i*m*(m+1)//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
num = [0 for i in range(n + 1)]
for i in range(n):
    for j in range(n // (i + 1)):
        num[(i + 1) * (j + 1)] += 1
ans = 0
for i in range(n):
    ans += (i + 1) * num[i + 1]
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

N = int(input())

cnt = [0] * (10 ** 7 + 1)

ans = 0

for i in range(1, N + 1):
    j = N // i
    ans += j * (j + 1) // 2 * i

print(ans)

Submission status: Accepted

Solution code:
from numba import jit, i8, void


@jit(i8(i8))
def g(n):
    return n * (n + 1) // 2


@jit(i8(i8))
def solve(n):
    ans = 0
    for i in range(1, n + 1):
        ans += i * g(n // i)
    return ans

def main():
    print(solve(int(input())))


main()