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

lis=[1 for i in range(10**7)]


for i in range(2,10**7+1):
    for j in range(1,(10**7)//i+1):
        lis[i*j-1]+=1
s=0
for i in range(n):
    s+=lis[i]*(i+1)

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys  

if __name__=='__main__':
  n = int(sys.stdin.readline().rstrip())
  l = [0]*n
  ans = 0
  for i in range(n):
    for j in range(i,n,(i+1)):
      ans += j+1
  print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
#S = input()
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

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

print(answer)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math


n = ni()

nums = [1]*(n+1)

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

for i in range(1,n+1):
    q = n//i
    ans += q*(q+1)//2*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:
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def getlistofstring(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)

# sys.setrecursionlimit(10**6)
# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):
N = int(input())
dp = [2] * (N+1)
dp[1] = 1
i = 2
while i < N:
    for j in range(2*i, N+1, i):
        dp[j] += 1
    i += 1
# print(dp[1:])
print(sum(i * dp[i] for i in range(1, N+1)))

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def primes(n):
    is_prime = [0] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 1
    for i in range(2, n+1):
        for j in range(i, n + 1, i):
            is_prime[j] += j
    return sum(is_prime)
    
n = int(input())
ans = 0
print(primes(n)+(n*(n+1)//2)-1)

Submission status: Accepted

Solution code:
N = int(input())

memo = list(range(N+1))

temp = [0]*(N+1)
temp[0] = 1
temp[1] = 1

for x,c in enumerate(memo):
    if temp[x] == 0:
        for y in range(x,N+1,x):
            memo[y] *= temp[y]+1
            temp[y] = 1
        k = 2
        while x**k <= N:
            for y in range(x**k,N+1,x**k):
                temp[y] += 1
            k += 1
    memo[x] *= temp[x]+1

print(sum(memo)-1)

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:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def num_divisors_table(n):
    table = [0 for i in range(n + 1)]
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

# ここから書き始める
n = int(input())

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



# ans2 = 0
# for i in range(1, n + 1):
#     d = make_divisors(i)
#     # print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
# //a(n) = Sum_{k=1..n} k/2 * floor(n/k) * floor(1 + n/k).
n = int(input())
sum=0
for i in range(1, n+1):
	k = i/2
	k=k*(n//i)
	k = k*(1+ (n//i))
	sum+=k
print(int(sum))

Submission status: Accepted

Solution code:
n = int(input())

r = 0

r0 = (1+n)*n-1
r = 0
for i in range(2, n//2+1):
    c = n // i
    s, e = i*2, i*c
    r += (c-1) * (s+e) // 2
print(r0+r)

Submission status: Accepted

Solution code:
n = int(input())
d = [1 for _ in range(n+1)]

for i in range(2,n+1):
  for j in range(1,n//i+1):
    a = i*j
    if a > n:
      break
    d[a] += 1
ans = 0
for k in range(1,n+1):
  ans += k*d[k]
print(ans)

Submission status: Accepted

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

S=[0]*(N+1)
T=0
for i in range(1,N+1):
    T+=i
    S[i]=T
    
for i in range(1,N+1):
    W+=i*S[N//i]
print(W)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    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)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
from collections import deque
import collections
import heapq
import json
N=int(input())
l=[0]*(N+1)

for i in range(1,N+1):
    for j in range(i,N+1,i):
        l[j]=l[j]+1
#print(l)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

n = int(input())
fri = [0]*(n+1)
for i in range(1, n+1):
    for j in range(i, n+1, i):
        fri[j] += 1
ans = 0
for i in range(1, n+1):
    ans += i * fri[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
from math import isqrt

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()

import math

def sieve_of_eratosthenes(n):
    prime_list = []  # n以下の素数のリスト
    A = [1]*(n+1)    # A[i] = iが素数なら1,その他は0
    A[0] = A[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if A[i]:
            prime_list.append(i)
            for j in range(i**2,n+1,i):
                A[j] = 0
    for i in range(math.floor(math.sqrt(n))+1,n+1):
        if A[i] == 1:
            prime_list.append(i)
    return prime_list

primelist = sieve_of_eratosthenes(N)

list = [i for i in range(N+1)]

for p in primelist:
    a = p
    r = 2
    while a <= N:
        for i in range(1,N//a+1):
            if i % p == 0:
                continue
            else:
                list[a*i] *= r
        a *= p
        r += 1

print(sum(list))

Submission status: Accepted

Solution code:
import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n=r()
a=[1]*(n+1)
cnt=1
for i in range(2,n+1):
    for j in range(i,n+1,i):
        a[j]+=1
    cnt+=i*a[i]
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())

ans=0
if n==1:
    ans=1
else:

    yakusuu=[1]*(n+1)

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

        while(num<=n):
            yakusuu[num]+=1
            num=num+i
    
    for i in range(1,n+1):
        ans+=yakusuu[i]*i

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

cnt = [1] * n
for i in range(2, n + 1):
    for j in range(i - 1, n, i):
        cnt[j] += 1
print(sum((i + 1) * cnt[i] for i in range(n)))

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:
def do():
    if n == 1:
        print(1)
        return 0
    x = (1+n) * n
    x -= 1
    #print(x) # なにもない時の和
    for i in range(2, (n // 2) + 1):
        num = n // i
        x += i * ( (1 + num) * num // 2)
        x -= i
        #for j in range(i+i, n + 1, i):
        #    x += j

    print(x)

res = 0
n = int(input())
do()

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N=ii()
    d = [0] * (N+1)
    ans = 0
    for i in range(1, N+1):
        for j in range(i, N+1, i):
            d[j] += 1
        ans += i * d[i]
    print(ans)


main()

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,N//2+1):
        j = 2
        while i * j <= N:
            d[i*j] += 1
            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:
import math
# N, M, K = [int(_) for _ in input().split()]
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

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

Submission status: Accepted

Solution code:
from math import floor
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def num_divisors(n):
    i = 1
    result = 0
    while i * i <= n:
        if n % i == 0:
            result += 2 if n // i != i else 1
        i += 1
    return result


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

    return int(result)


if __name__ == "__main__":
    n = int_in()
    out(solve(n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = sum(i*n for i,n in enumerate(checked))

print(ans)

Submission status: Accepted

Solution code:
import sys 

n = int(input())

sum = 0

for i in range(1, n + 1):
	last = n // i * i 
	count = (last - i) // i + 1

	#print(last, count)

	s = (i + last)  * count // 2 
	#print(s)
	sum += s

print(sum)

Submission status: Accepted

Solution code:
N=int(input())

ans=[1]*N
for i in range(2,N+1):
    tmp=i
    while tmp-1<N:
        ans[tmp-1]+=1
        tmp+=i
anss=0
for i in range(1,N+1):
    anss+=i*ans[i-1]
print(anss)

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:
def main():
    N = int(input())
    S =0
    for i in range(1,N+1):
        S  += (i+(N-N%i))*(N//i)//2

    print(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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
n=int(input())
ans=0
for i,j in enumerate(num_divisors_table(n)):
  ans+=i*j
print(ans)

Submission status: Accepted

Solution code:
#!python3

# input
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


def main():
    t = num_divisors_table(N)
    ans = sum([i * x for i, x in enumerate(t)])
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    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__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

    print(ans)

main()

Submission status: Accepted

Solution code:
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
N = int(input())
a = num_divisors_table(N)
ans = 0
for i in range(N+1):
  ans += i*a[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

M = 10**7+5
cnt = [0] * M

for i in range(1, n+1):
    for j in range(i, M, 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 bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())


ans=0
for i in range(n):
    tmp=n//(i+1)
    ans+=(i+1)*tmp*(tmp+1)//2
    # print(tmp)
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+1)*n//2
print(ans)

Submission status: Accepted

Solution code:

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd

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

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np


def solve(inp):
    n = inp[0]
    ans = n * (n + 1) // 2
    for i in range(2, n + 1):
        k = n // i
        ans += i * k * (k + 1) // 2
    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)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def eratosthenes_sieve(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

N = INT()

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

Submission status: Accepted

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

import math
from collections import Counter
import array

class Sieve:
    def __init__(self, n=10**7+100):
        self.N = n

        self.nd = array.array('i', [1] * n)

        for i in range(2, n):
            for j in range(i, n, i): 
                self.nd[j] += 1
    
    def primes(self):
        return [i for i, e in enumerate(self.s) if e == -1 and i >= 2]

    def fastfactorize(self, n):
        assert(n <= self.N)

        ret = []

        while self.s[n] != -1:
            ret += [self.s[n]]
            n = n // self.s[n]

        ret += [n]

        return ret

    def isprime(self, n):
        if n < self.N:
            return self.s[n] == -1
        for p in self.PRIMES:
            if p*p > n:
                return True
            if n % p == 0:
                return False

    def numDivisors(self, n):
        if n == 1: return 1

        c = dict()

        for f in self.fastfactorize(n):
            if f not in c: c[f] = 0
            c[f] += 1

        ret = 1
        for p in c:
            ret *= (c[p] + 1)
        return ret

    def factorize(self, n):
        if n < self.N:
            return self.fastfactorize(n)
        
        for p in self.PRIMES:
            if p*p > n:
                break
            if n % p == 0:
                return [p] + self.factorize(n // p)

        return [n]

N = int(input())

sieve = Sieve()

ans = 0

for k in range(1, N+1):
    ans += k*sieve.nd[k]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dp = [0 for _ in range(n + 1)]
ans = 0
for i in range(n + 1):
    if i > 0:
        for j in range(i, n + 1, i):
            dp[j] += 1
    ans += i * dp[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N = int(input())

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

main()

Submission status: Accepted

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

N, = map(int, input().split())

ans = 0

ans = 0
for k in range(N, 0, -1):
    mi = int(N/k)
    sum_num = (1+mi) * (mi//2) if mi%2==0 else mi * ((mi-1)//2) + mi
    ans += k * sum_num

print(ans)

Submission status: Accepted

Solution code:
def prime_factorize(N):
    ans = 0
    f = 1
    while f <= N:
        ans += f * (N//f) * (N//f+1) //2

        f += 1
    return ans

def main():
    N = int(input())
    ans = prime_factorize(N)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
dp = [2]*n
dp[0]=1
ans = 1

if n == 1:
  print(1)
  quit()
  
for i in range(1, n):
  ans += (i+1)*dp[i]
  temp = (i+1)*2 #2→4
  while temp <= n: #4
    dp[temp-1]+=1
    temp += i+1 #6
#print(dp)
print(ans)

Submission status: Accepted

Solution code:
## coding: UTF-8
MAX = 10**7+10
#MAX = 101
fac = [0] * (MAX+1)

N = int(input())

for i in range(1, MAX):
    for j in range(1, MAX):
        try:
            fac[i*j] += 1
        except IndexError: #終了条件が難しいイテレータについて、リストの範囲外に出た瞬間にIndexErrorを検知してbreakする実装
            break

ans = [1]
for i in range(2, MAX):
    ans.append(ans[-1] + i * fac[i])

print(ans[N-1])
#print(ans[:10])
#print(fac[:100])







'''
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

now = 1
ans = [1]

for i in range(2, 10**7+1):
    now += i * len(make_divisors(i))
    #print(make_divisors(i))
    ans.append(now)

print(ans[:10])
'''
'''
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    ret = 1
    for i in range(len(arr)):
        ret *= (arr[i][1] + 1)
    return ret

now = 1
ans = [1]

for i in range(2, 10**7+1):
    now += i * factorization(i)
    #print(i, factorization(i))
    ans.append(now)

print(len(ans))
'''

Submission status: Accepted

Solution code:
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

def eratos2(n):
	ans = n*(n+1)//2
	#print(ans)
	for i in range(2,n+1):
		#ans += (n+1)//i
		ans += (n//i)*(2*i+(n//i-1)*i)//2
		#print(ans)
	return ans

print(eratos2(readInt()))

Submission status: Accepted

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

cum_l = []

s = 0
for i in range(1,10000001):
    s += i
    cum_l.append(s)

ans = 0 
for i in range(1,n+1):
    k = n // i
    ans += (i*(cum_l[k-1]))

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
li=[1 for _ in range(10**7+1)]
ans=1

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

Submission status: Accepted

Solution code:
N = int(input())

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