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:
# -*- coding: utf-8 -*-
# D

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
import itertools
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n = int(input())

    #output
    answer = n*(n+1)//2
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            answer += j

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin,stdout
from numba import njit
@njit
def solve(n):
	fctrs=[0]*(n+1)
	ans=0
	for i in range(1,n+1):
		for j in range(i,n+1,i):
			fctrs[j]+=1
	for i in range(1,n+1):
		ans+=(i*fctrs[i])
	return ans
n=int(stdin.readline())
print(solve(n))

Submission status: Accepted

Solution code:
from numba import njit
@njit
def solve(n):
	fctrs=[0]*(n+1)
	ans=0
	for i in range(1,n+1):
		for j in range(i,n+1,i):
			fctrs[j]+=1
	for i in range(1,n+1):
		ans+=(i*fctrs[i])
	return ans
n=int(input())
print(solve(n))

Submission status: Accepted

Solution code:
mem = {}
def f(n):
	if n in mem:
		return mem[n]
	ans,b = 0, 1
	while(b <= n):
		k = n / b
		ans += b *k * (k + 1) / 2  
		b +=1
	mem[n] = ans
	return ans
print f(int(raw_input()))

Submission status: Accepted

Solution code:
def f(n):
	ans,b = 0, 1
	while(b <= n):
		k = n / b
		ans += b *k * (k + 1) / 2  
		b +=1
	return ans
print f(int(raw_input()))

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 = 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())

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

ans = sum(i * f(n // i) for i in range(1, n + 1))

print(ans)

Submission status: Accepted

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re


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

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

    print(math.floor(ans))
main_chk()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(): 
    N=int(input())
    ANS=0
    for i in range(1,N+1):
        ANS+=i*(N//i*(N//i+1)//2)
    print(ANS)
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:
from numba import njit
@njit("i8(i8)")

def solve(n):
  l=[1]*(n+1)
  ans=1
  for i in range(2,n+1):
    j=i
    while(j<=n):
      l[j-1]+=1
      j+=i
    ans+=(i*l[i-1])
  return ans

n=int(input())
print(solve(n))

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:
n = int(input())

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

print(int(res))

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
#coding: utf-8
N = int(input())
ans = 0
for i in range(1, N+1):
    Y = N // i
    ans += (Y * (Y + 1)) // 2 * i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

counter = 0
for n in range(1,N+1):
    a = N//n
    counter += a*(a+1)*n//2


print(counter)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ans = 0
 
    for i in range(1, n+1):
        y = n // i
        ans += (y+1)*y*i//2
    print(ans)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
for x in range(1,n+1):
    h = n//x
    ans += int(h*(h+1)/2)*x
print(ans)

Submission status: Accepted

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






if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        m = n//i
        ans += i*m*(m+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+=i*k*(k+1)//2
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = input_int()

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

    print(int(ans))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ans=0
for i in range(1,n+1):
  num=n//i
  ans+=((num*(num+1))//2)*i
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 * (j + 1) // 2)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = int(sum([i * (n // i + 1) * (n // i) / 2 for i in range(1, n+1)]))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
N = int(input())
 
Xarray = np.arange(1, N+1)
Xans = ((N // Xarray) * (2 * Xarray + ((N // Xarray) - 1) * Xarray)) // 2
 
print(np.sum(Xans))

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

#初項a、公差d=a、n項までの和
for a in range(1,N+1):
    n=N//a
    ans=(n*(2*a+(n-1)*a))//2+ans
print(ans)

Submission status: Accepted

Solution code:
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
N = rri()
ans= 0
for i in range(1, N+1):
    first = i
    last = i*(N//i)
    ans += (last+first)*(N//i)/2
print(ans)


#26879

Submission status: Accepted

Solution code:
n=int(input())
List=[2 for x in range(n+1)]
List[0]=0
List[1]=1
ans=1
 
for x in range(2,n+1):
  for y in range(2*x,n+1,x):
    List[y]+=1
  ans+=x*List[x]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
List=[2 for x in range(n+1)]
List[0]=0
List[1]=1
ans=1

for x in range(2,n+1):
  for y in range(2*x,n+1,x):
    List[y]+=1
  ans+=x*List[x]
print(ans)

Submission status: Accepted

Solution code:
def g(x):
    return (x*(x+1))//2
    
n = int(input())
ans = 0

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

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

j=2
while j<=N:
    k=2
    while j*k<=N:
        ans+=j*k
        k+=1
    j+=1

print(ans-1)

Submission status: Accepted

Solution code:
#エラストテネスの篩(最大の素因数を格納した配列)
def make_eratosthenes(n):
    A=[0]*n
    A[0],A[1]=-1,-1 #0と1は対象外
    for i in range(2,n):
        if A[i]==0:
            j=i
            while j<n:
                A[j]=i
                j+=i
    return A

n=int(input())
E=make_eratosthenes(n+5)
C=[0]*(n+5)
C[1]=1
D=[0]*(n+5) #重複判定
for i in range(2,n+5):
    e=i//E[i]
    if e==1:
        C[i]=2
        D[i]=1
    else:
        if E[e]==E[i]:
            C[i]=C[e]+D[e]
            D[i]=D[e]
        else:
            C[i]=C[e]*2
            D[i]=C[e]
ans=0
for i in range(n+1):
    ans+=i*C[i]
print(ans)

Submission status: Accepted

Solution code:
from numba import njit

@njit("i8(i8)")
def solve(n):
    s = [1] * (n+1)
    ans = 1
    for i in range(2,n+1):
        for j in range(i,n+1,i):
            s[j] += 1
        ans += (i * s[i])
    return ans
n = int(input()) 
print(solve(n))

Submission status: Accepted

Solution code:
from numba import njit
import numpy as np


@njit("i8(i8)")
def solve(n):
    ans = 1
    res = np.ones(n + 1, dtype=np.int64)
    for i in range(2, n + 1):
        for j in range(i, n + 1, i):
            res[j] += 1
        ans += i * res[i]
    return ans


N = int(input())
print(solve(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

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

Submission status: Accepted

Solution code:
# D - Sum of Divisors

n = int(input())

# n以下の1の倍数 ... n個, それぞれk倍して加算 ... n * (n+1) // 2
# n以下のmの倍数 ... n//m個, それぞれk倍して加算 ... m * (n // m) * (n // m + 1) // 2

s = sum(m * (n // m) * (n // m + 1) // 2 for m in range(1, n + 1))
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

res = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    y = [0]*(n+1)
    res = 0
    for i in range(1,n+1):
        j = 1
        while True:
            if i*j > n:
                break
            y[i*j] += 1
            j += 1
        res += i*y[i]
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
# from collections import Counter, deque
# from collections import defaultdict
# from itertools import combinations, permutations, accumulate, groupby, product
# from bisect import bisect_left,bisect_right
# from heapq import heapify, heappop, heappush
# from math import floor, ceil,pi,factorial
# from operator import itemgetter
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9 + 7


n = int(input())
def f(n): return n*(n+1)//2
ans = 0
for i in range(1,n+1):
    x=n//i
    ans+=i*f(x)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
x = math.floor(math.sqrt(n))
ans = 0
for m in range(1,x+1):
    ans += m*(m+math.floor(n/m))*(math.floor(n/m)+1-m)
print(int(ans-(((x+1)**4-x**4)-((x+1)**2-x**2))/12))

Submission status: Accepted

Solution code:
import math
def solver(n):
    sum = 0
    for i in range(1,n+1):
        y = math.floor(n/i)
        sum+=(i*y*(y+1)/2)
    return int(sum)


n = int(input())
print(solver(n))

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

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

for n in range(N):
	d = N//(n+1)
	r += d*(d+1)*(n+1)//2
print(r)

Submission status: Accepted

Solution code:
from numba import njit
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

@njit
def main(N):
    ans = 0

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

    print(ans)


if __name__ == "__main__":
    N = int(readline())
    main(N)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main(N):
    ans = 0

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

    print(ans)


if __name__ == "__main__":
    N = int(readline())
    main(N)

Submission status: Accepted

Solution code:
#from numba import njit

n = int(input())


#@njit
def f(n):
    ret = 0
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            ret += j

    return ret


ans = f(n)
print(ans)

Submission status: Accepted

Solution code:
from numba import njit

n = int(input())


@njit
def f(n):
    ret = 0
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            ret += j

    return ret


ans = f(n)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
 
def num_divisors_table(N):
    ans = 0
    for i in range(1, N + 1):
        u = i
        t = i * (N // i)
        n = N // i
        ans += (u + t) * n // 2
    
    return ans

print(num_divisors_table(N))

Submission status: Accepted

Solution code:
N = int(input())
 
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    ans = 0
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            ans += j
    
    return ans

print(num_divisors_table(N))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N = int(readline())
    f = [0 for _ in range(N+1)]
    for i in range(1, N+1):
        j = i
        while j <=N:  
            f[j] += 1
            j += i
    ans = 0
    for i in range(1, N+1):
        ans += i*f[i]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main(N):
    ans = N * (N + 1) // 2

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

    print(ans)


if __name__ == "__main__":
    N = int(readline())
    main(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from numba import njit
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

@njit
def main(N):
    ans = N * (N + 1) // 2

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

    print(ans)


if __name__ == "__main__":
    N = int(readline())
    main(N)

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:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy
import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputintlist(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloatlist(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]

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

Submission status: Accepted

Solution code:
from numba import njit
from math import sqrt
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

@njit
def main(N):
    table = [1] * (N + 1)

    for n in range(2,N):
        for i in range(2*n, N+1, n):
            table[i] += 1
    
    ans = 0
    for i in range(1, N+1):
        ans += i * (table[i] + 1)
    
    print(ans - 1)


if __name__ == "__main__":
    N = int(readline())
    main(N)

Submission status: Accepted

Solution code:
import numpy as np
from numba import njit


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


N = int(input())
print(solve(N))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def solve(stdin):
    n = stdin[0]
    dp = np.zeros(n+1,dtype=np.int64)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            dp[j]+=1
    dp*=np.arange(n+1)
    return dp.sum()

def main():
    stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    print(solve(stdin))

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    l = [0 for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            l[j] += 1
    answer = 0
    for i in range(n + 1):
        answer += i * l[i]
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    ans = 0
    for i in range(1,N+1):
        for j in range(i,N+1,i):
            ans += j
    return ans

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
f = [0] * (N+1)
for i in range(1, N+1):
  for j in range(i, N+1, i):
    f[j] += 1

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

Submission status: Accepted

Solution code:
import collections

n = int(input())

f = [1] * (n + 1)
for i in range(2, n + 1):
    if f[i] != 1: continue
    m = i
    while m <= n:
        tmp = m
        cnt = 0
        while tmp % i == 0:
            tmp = tmp // i
            cnt += 1
        f[m] *= cnt + 1
        m += i

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math


def solve(N: int):
    answer = 0
    for i in range(1, N+1):
        ratio = N // i
        answer += i * (ratio * (ratio + 1)) // 2
    print(answer)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# n/(m+1) < x <= n/m
# (n//(m+1), n//m]
# [n//(m+1) + 1, n//m]

n = int(input())
ans = 0
i = 1
while i * i < n:
    m = n // i
    ans += i * m * (m + 1) // 2
    i += 1
m = n // i
while m:
    s = (n//(m+1) + 1 + n//m) * (n//m - n//(m+1)) // 2
    ans += s * m * (m + 1) // 2
    m -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

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

ans=0

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ans = 0
    for i in range(1, n+1):
        # y = n // i
        # y = (y+1)*y*i//2
        ans += ((n//i)+1) * (n//i) * i // 2
    print(ans)
    
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 += (x*(x+1)//2)*i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def g(num):
    return (num*(num+1)) // 2

def f(num):
    return num * g(n//num)

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