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:
n=int(input())
ans=n*(n+1)//2

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

print(ans)

Submission status: Accepted

Solution code:
def sums(N):
    """ sum of 1~N"""
    return N*(N+1)//2

N=int(input())
ans=0
for i in range(1,N+1):
    nn=N//i
    ans+=sums(nn)*i
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a = [i for i in range(n+1)]
res=0
time = 0
for i in range(1,n+1):
  cnt = n // a[i]
  res += a[i]*cnt*(cnt+1)//2
  #print(res)

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
def wa(k,n):
  m=(n-n%k)//k
  return k*(m*(m+1)//2)
ans=0
for i in range(1,n+1):
  ans+=wa(i,n)
print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


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

Submission status: Accepted

Solution code:
n=int(input())
ans=0
i=1
while i*2<=n:
    temp=(n//i)
    temp2=temp*(temp+1)//2
    ans+=i*temp2
    i+=1
ans+=(i+n)*(n-i+1)//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans + (N + N//2 + 1) * (N - N//2) // 2)

Submission status: Accepted

Solution code:
N = int(input())

count = 0
import math

for i in range (1, N+1):
	P = math.floor(N/i)
	count+=i*int(P*(P+1)/2)

print(count)

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:
N = int(input())
ans = N * (N + 1) // 2
for i in range(2, N + 1):
    p = N // i
    ans += i * (p * (p + 1) // 2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def g(x):
    return int(0.5 * x * (x+1))

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [1] * (10**7+1)
for i in range(1,n+1):
    for i in range(2*i,n+1,i):
        a[i] += 1
ans = 0
for i in range(n+1):
    ans += i*a[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dp = [0]*(n+1)
ans = 0
for i in range(1,n+1):
    k = 1
    while i*k<=n:
        dp[i*k] += 1
        k += 1
    ans += i*dp[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

f = [1] + [2] * (N - 1)
ans = 1
for i in range(1, N):
    k = i + 1
    ans += k * f[i]
    for j in range(k * 2 - 1, N, k):
        f[j] += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def num_divisors_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

divs = num_divisors_table(n)

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

print(res)

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(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

div_cnt = [2] * n
div_cnt[0] = 1

for i in range(2, n + 1):
    j = 2 * i
    while j < n + 1:
        div_cnt[j - 1] += 1
        j += i


res = 0
for i in range(n):
    res += (i + 1) * div_cnt[i]

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

def solve():
    n = int(input())

    def num_divisors_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


    table = num_divisors_table(n)

    ans = 0

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

    print(ans)
solve()

Submission status: Accepted

Solution code:
def main(N):
    ans = 0
    for i in range(N):
        num = N//(i+1)
        numsum = (num*(num+1))//2
        numsum *= (i+1)
        ans += numsum

    return ans


N = int(input())
print(main(N))

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 num in range(1, n+1):
    count = n // num
    last = count * num
    total = count * (num + last) // 2
    ans += total

print(ans)

Submission status: Accepted

Solution code:
N=10**7
llist=[0]*(N+1)
for i in range(1,N+1):
  for j in range(i,N+1,i):
    llist[j]+=1
dp=[0]*(N+1)
for i in range(1,N+1):
  dp[i]=dp[i-1]+llist[i]*i
N=int(input())
print(dp[N])

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for i in range(1, N + 1):
    num = N // i #個数
    tmp = num * (num + 1) // 2
    ans += tmp * i

print (ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF = 10**20
def main():
    N=ii()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
dp=[0 for _ in range(n+1)]
for j in range(1,n+1):
    i = 1
    while j*i<=n:
        dp[j*i] += j*i
        i+=1

print(sum(dp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b = [1]*(10**7+1)
for i in range(2, n+1):
    for j in range(i, 10**7+1, i):
        b[j] += 1
ans = 0
for i in range(1, n+1):
    ans += (i*b[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

num = [0] * (n + 1)
for i in range(1, n // 2 + 1):
    for j in range(i, n + 1, i):
        num[j] += 1
for i in range(n // 2 + 1, n + 1):
    num[i] += 1
    
ans = 0
for i in range(n + 1):
    ans += i * num[i]
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    ans = 0
    for i in range(1,N + 1):
        for j in range(i,N + 1,i):
            ans += j
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def s(n):
  return (n*(n+1))//2

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

Submission status: Accepted

Solution code:
# @author 

import sys

class DSumOfDivisors:
    def solve(self, tc=0):
        # def divCount(n):
        # 
        #     # sieve method for
        #     # prime calculation
        #     hh = [1] * (n + 1);
        # 
        #     p = 2;
        #     while ((p * p) < n):
        #         if (hh[p] == 1):
        #             for i in range((p * 2), n, p):
        #                 hh[i] = 0;
        #         p += 1;
        # 
        #         # Traversing through
        #     # all prime numbers
        #     total = 1;
        #     for p in range(2, n + 1):
        #         if (hh[p] == 1):
        # 
        #             # calculate number of divisor
        #             # with formula total div =
        #             # (p1+1) * (p2+1) *.....* (pn+1)
        #             # where n = (a1^p1)*(a2^p2)....
        #             # *(an^pn) ai being prime divisor
        #             # for n and pi are their respective
        #             # power in factorization
        #             count = 0;
        #             if (n % p == 0):
        #                 while (n % p == 0):
        #                     n = int(n / p);
        #                     count += 1;
        #                 total *= (count + 1);
        # 
        #     return total;
        # 
        # so_far = 0
        # for i in range(1, 10):
        #     d = divCount(i)
        #     so_far += d * i
        #     print(so_far, end=',')

        n = int(input())

        print(int(sum(k/2 * int(n/k) * int(1 + n/k) for k in range(1, n + 1))))


solver = DSumOfDivisors()
input = sys.stdin.readline

solver.solve()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    ans = 0
    for i in range(1,n+1):
        ni = n//i
        ans += i*ni*(ni+1)//2
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import unittest


def solve(n):
    total = 0
    for i in range(1, n+1):
        k = n // i
        total += i * k * (k + 1) // 2

    return total


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


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test1(self):
        self.assertEqual(solve(1), 1)
        self.assertEqual(solve(2), 5)
        self.assertEqual(solve(3), 11)
        self.assertEqual(solve(4), 23)

    def test2(self):
        self.assertEqual(solve(100), 26879)

    def test3(self):
        self.assertEqual(solve(10000000), 838627288460105)

Submission status: Accepted

Solution code:
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')



def solve():
    
    # for _ in range(ii()):

    s=1
    n=ii()
    a=[2]*(n+1)
    for j in range(2,n+1):
        for k in range(2*j,n+1,j):
            a[k]+=1
    for i in range(2,n+1):
        s+=i*a[i]
    print(s)
    










        
if __name__ =="__main__":

    if path.exists('input.txt'):
        sys.stdin=open('input.txt', 'r')
        sys.stdout=open('output.txt','w')
    else:
        input=sys.stdin.readline
    solve()

Submission status: Accepted

Solution code:
import sys
import  math
from heapq import *
import fractions
import bisect
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

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


# for i in range(2,n+1):
#     base = i
#     while True:
#         buf[base] += 1
#         base += base
#         if base > n:
#             break
#
# print(buf)
#
# ans = 0
# for i in range(1,n+1):
#     ans += i*buf[i]
#
# 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(a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
# エラトステネスの篩
N = int(input())

sieve = [0] * (N + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, N + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, N + 1, i):
        if sieve[j] == 0:
            sieve[j] = i


def f(K):
    t = []
    a = K
    while a != 1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    result = 1
    for _, n in t:
        result *= (n + 1)
    return result


result = 0
for K in range(1, N + 1):
    result += K * f(K)
print(result)

Submission status: Accepted

Solution code:
'''import math
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
pa=[0]*n
pb=[0]*m
pa=[a[0]]
pb=[b[0]]
for i in range(n):
	pa[i]=pa[i-1]+a[i]
for i in range(m):
	pb[i]=pb[i-1]+b[i]

'''
n=int(input())
l=[0]*(n+1)
for i in range(1,n+1):
	for j in range(i,n+1,i):
		l[j]+=1

s=0

for i in range(1,n+1):
	s+=i*l[i]
print(s)

Submission status: Accepted

Solution code:
n = int(input())

answer = 0
for k in range(1, n // 2 + 1):
    m = n // k
    answer += k * m * (m + 1) // 2

m = (n // 2 + 1)
answer += (m + n) * (n - m + 1) // 2

print(answer)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""


def make_primes(n): #nまでの素数列挙
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass  


def prime_decomposition(n): #素因数分解
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table

def make_divisors(n): #約数列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return len(divisors)


n = onem()
po = [1 for i in range(10**7+1)]

for i in range(n+1):
	if i == 0 or i == 1:
		continue
	for j in range(i,n+1,i):
		po[j] += 1
an = 0

for i in range(n+1):
	an += po[i]*i
print(an)

Submission status: Accepted

Solution code:
N = int(input())

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

print(res)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())

    div_num = [1] * (N+1)
    ans = 0
    for i in range(1, N+1):
        ans += i * div_num[i]
        for j in range(2, N+1):
            if i*j > N:
                break
            div_num[i*j] += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache
from numba import jit

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

@jit
def main():
	n = I()
	ans = 0
	for k in range(1,n+1):
		ans += k * 0.5 * (n // k) * (n // k + 1)
	print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np
#import bisect

def main():

	n=II()

	ans=0

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

	print(ans)











if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n = int(input())

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

print(
  sum(
    list( (n//i) *(n//i + 1) //2 * i  for i in range(1, n+1))
  )
)

Submission status: Accepted

Solution code:
N = int(input())

cur = 2
ans = N*(N+1)//2
while cur <= N:
    n = N//cur
    ans += cur * (n+1) * n // 2
    cur += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

s = 0
for divisor in range(1, N+1):
    num = N // divisor
    tmp = num * divisor
    s += tmp * (num + 1) // 2

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examA():
    N = I()
    ans = N + N**2 + N**3
    print(ans)
    return

def examB():
    S = SI()
    T = SI()
    ans = 0
    for s,t in zip(S,T):
        if s!=t:
            ans += 1
    print(ans)
    return

def examC():
    N, M, K = LI()
    A = LI()
    B = LI()
    SA = 0
    b = 0
    SB = 0
    for i in range(M):
        if SB+B[i]>K:
            break
        SB += B[i]
        b += 1
    #print(b,SB)
    ans = 0
    ans = max(ans,b)
    for i in range(N):
        SA += A[i]
        if SA+SB>K:
            while(b>=0):
                if SA+SB<=K:
                    break
                SB -= B[b-1]
                b -= 1
        if b==-1:
            break
        #print(i,b,SA,SB)

        ans = max(ans,b+i+1)
    print(ans)
    return

def examD():
    def primes(n):
        is_prime = [True] * (n + 1)
        is_prime[0] = False
        is_prime[1] = False
        for i in range(2, int(n ** 0.5) + 1):
            if not is_prime[i]:
                continue
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False
        return [i for i in range(n + 1) if is_prime[i]]
    N = I()
    P = primes(N)
    #print(P)
    D = [1]*(N+1)
    for p in P:
        for i in range(1,1+N//p):
            cnt = 1
            cur = i
            while(cur%p==0):
                cnt += 1
                cur //= p
            D[p*i] *= (1+cnt)

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

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


n = int(input())
num = 0
for i in range(1, n+1):
    last = (n - (n%i))//i
    num += (i * last * (last+1) // 2)

print(num)

Submission status: Accepted

Solution code:
n = int(input())


def div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


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

print(ans)

Submission status: Accepted

Solution code:
import math

N = int(input())

M = [2] * (N+1)
M[1] = 1

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

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

print(ans)