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:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

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

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

n = int(input())
def f(x, y):
    k = n // y
    return x + k * (y + y * k) // 2

ans = reduce(f, range(n + 1))
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):
    a = n//i
    ans += i*(a*(a+1)//2)
print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
import string
def main():  #startline-------------------------------------------
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        x = n // i
        ans += x * (i + i * x) // 2
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    
    ans = 0
    for X in range(1,N+1):
        Y = int(N/X)
        ans += (Y*(Y+1)*X)//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)

Submission status: Accepted

Solution code:
n = int(input())

# エラストテネス
def divisor(N):
    div = [0] * (N + 1)
    for n in range(1, N + 1):
      for m in range(n, N + 1, n):
        div[m] += m
    return sum(div)

print(divisor(n))

Submission status: Accepted

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    N=int(input())

    # divisors=sieve(N)
    #
    # # print(divisors)
    # sum=0
    # for i,n in enumerate(divisors):
    #     sum+=i*n

    # print(5*(2+5-1)//2)
    print(sieve(N))

def sieve(n):
    # is_prime = [i for i in range(n+1)]
    sum=n*(2+n-1)//2
    # sum=0

    for i in range(2, n+1):
        # print(is_prime)
        d=n//i
        # print(d)
        sum+=d*((d+1)*i)//2
        # sum += i
        # j = 2 * i
        # while j <= n:
        #     sum += j
        #     j += i

    return sum


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import collections
def main():

    N = int(input())
    d = dict()
    for i in range(1, N+1):
        d[i] = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

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

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def calc(b,e):
    cnt = e // b
    return (b+e) * cnt//2


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

print(ans)

Submission status: Accepted

Solution code:
print(list(map(lambda N:sum([((N//i)*(N//i+1)//2)*i for i in range(1,N+1)]),[int(input())]))[0])

Submission status: Accepted

Solution code:
n = int(input())

dp = [1 for _ in range(n+1)]

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

ans = 0

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

print(ans)

Submission status: Accepted

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

    ans = 0

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

    print(ans)

if __name__ == "__main__":
    main()

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

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



print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    
    ans = 0
    for i in range(1, N + 1):
        j = N // i
        ans += j * (j + 1) * i // 2
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def readinput():
    n=int(input())
    return n

def main(n):
    fk=[1]*(n+1)
    for i in range(2,n+1):
        j=i
        while(j<=n):
            fk[j]+=1
            j+=i
    sum=0
    for i in range(1,n+1):
        sum+=i*fk[i]
    return sum

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input().strip())
    ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for d in range(1, N + 1):
    c = N // d
    ans += d * c * (c + 1)
ans //= 2
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(ans)

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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:
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    ll=[0]*(n+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            ll[j]+=1
    

    ans=0
    for k,v in enumerate(ll):
        if k==0: continue
        ans+=k*v

    print(ans)
        

    
resolve()

Submission status: Accepted

Solution code:
from numba import jit
@jit(cache = True)
def main():
    n=int(input())
    ans=0
    for i in range(1,n+1):
        x=n//i
        ans+=i*(x+1)*x//2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

N = int(input())

lis = [0] * (N+1)

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

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

    ans += i * lis[i]

print (ans)

Submission status: Accepted

Solution code:

N = int(input())

f = [2] * (N+1)
f[0] = 0
f[1] = 1
for k in range(2, int(N**0.5)+1):
  if f[k] > 2:
    continue
  m = 1
  while k ** m <= N:
    for j in range(1, N//k**m + 1):
      f[j * k**m] = f[j] * (m+1)
    m += 1
  #print(f)
#print(k)
ans = 0
for i, ff in enumerate(f):
  ans+=i*ff
print(ans)

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

ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for j in range(1, n+1):
  count = n//j
  ans += count*((count * j) + j)//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())
DP=[0 for _ in range(n+1)]

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

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

Submission status: Accepted

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

N = int(input())

ans = 0

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

Submission status: Accepted

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

print(sm)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    ll=[0]*(n+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            ll[j]+=1
    

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

    print(ans)
        

    
resolve()

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()

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:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())

vals = [1]*(N)
for num in range(1, N//2+1):
    mlt = 2
    # print('num', num)
    while num*(mlt) <= N:
        v = num*mlt
        # print(' v', v)
        vals[v-1] += 1
        mlt += 1

# print(vals)

cnt = 0
for ind, val in enu(vals):
    cnt += (ind+1)*val
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for X in range(1, N+1):
  Y = N // X
  ans += Y * (Y + 1) // 2 * X
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+1)*x//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)//2*i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

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 main():
    n=int(input())
    total=0
    for i in range(1,n+1):
        maxint=n//i
        total+=maxint*(maxint+1)*i//2
    print(total)


if __name__ == "__main__":

    main()

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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def lii(): return list(map(int, input().split()))
def lfi(): return list(map(float, input().split()))
def vvi(a,b,d): return [[d] * a for i in range(b)]

inf = 10**18
mod = 10**9+7

n = ii()
ans = 0
for i in range(n):
    a = i+1
    t = n//a
    ans += a*t*(t+1)//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    nums = list(range(1,n+1))
    ans = 0
    for num in nums:
        cnt = n//num
        curr_sum = cnt*(2*num+(cnt-1)*num)//2
        ans += curr_sum
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

a = 0
def g(x):
    y = N//x
    return y * (y+1)*x//2

print(sum(g(x) for x in range(1,N+1)))

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

ans = 0

if N == 1:
    print(1)
    exit()
if N == 2:
    print(5)
    exit()
if N == 3:
    print(11)
    exit()

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    ret = 0
    for i in range(1,N+1):
        x = (N//i)
        ret += x*(x+1)*i//2
    print(ret)

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)*(N//i+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+1)*X//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
def resolve():
    import math
    n = int(input())
    ans = 0
    for i in range(1, n+1):
        count = math.floor(n/i)
        last = int(math.floor(n/i) * i)
        ans += (i+last)*count//2
    print(ans)

resolve()

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit

n = int(input())
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from math import floor

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
num=list(range(1,n+1))
num=np.array(num)
x=n//num
ans=num*(x+1)*x/2
print(int(np.sum(ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

yakusu=[0]*(n+1)

for i in range(1,n+1):
    for j in range(1,n+1):
        if i*j<=n:
            yakusu[i*j]+=1
        else:
            break

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

print(ans)

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:

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

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

  print(ans)


main()

Submission status: Accepted

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

    ctr = [1] * (N + 1)
    for d in range(2, N + 1):
        j = d
        while j <= N:
            ctr[j] += 1
            j += d

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(readline())
    res = 0
    for x in range(1, N+1):
        y = N // x
        res += y * (y + 1) * x // 2
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sieve(n):
    count = [2] * (n+1)
    count[1] = 1

    p = 0
    for i in range(2,n+1):
        p = i
        for j in range(p+p, n+1, p):
            count[j] += 1
    
    return count

def solve():
    N = int(input())
    sieve_res = sieve(N)
    ans = 0
    for i in range(1,N+1):
        ans += i * sieve_res[i]
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
import math
## 素数判定 O (√n)

n = I()
ans = 0
yaku = [1] *(10**7+1)
yaku[0] = 0
yaku[1] = 1
for i in range(1,n+1):
    for j in range(i*2,n+1,i):
        yaku[j] += 1
for i in range(1,n+1):
    y = yaku[i]
    ans += i * y
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

    
def main():
    n = ni()
    ans = 0
    for x in range(1,n+1):
        nx = n//x
        ans += (nx+1)*nx*x//2
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    N=int(sys.stdin.readline())
    r=0
    for i in range(1,N+1):
        r+=(i+N-N%i)*(N//i)//2

    print(r)

    
main()

Submission status: Accepted

Solution code:
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys  
 
if __name__=='__main__':
  n = int(sys.stdin.readline().rstrip())
  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:
N = int(input())

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  ans = 0
  SQRT = int(n ** 0.5)
  for m in range(1,SQRT + 1):
    b = int(n/m)
    ans += m * (m + b) * (b + 1 - m)
  ans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6
  print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Python3 program to count 
# number of factors 
# of an array of integers 
MAX = 10000001; 

# array to store 
# prime factors 
factor = [0]*(MAX + 1); 

# function to generate all 
# prime factors of numbers 
# from 1 to 10^6 
def generatePrimeFactors(): 
	factor[1] = 1; 

	# Initializes all the 
	# positions with their value. 
	for i in range(2,MAX): 
		factor[i] = i; 

	# Initializes all 
	# multiples of 2 with 2 
	for i in range(4,MAX,2): 
		factor[i] = 2; 

	# A modified version of 
	# Sieve of Eratosthenes 
	# to store the smallest 
	# prime factor that divides 
	# every number. 
	i = 3; 
	while(i * i < MAX): 
		# check if it has 
		# no prime factor. 
		if (factor[i] == i): 
			# Initializes of j 
			# starting from i*i 
			j = i * i; 
			while(j < MAX): 
				# if it has no prime factor 
				# before, then stores the 
				# smallest prime divisor 
				if (factor[j] == j): 
					factor[j] = i; 
				j += i; 
		i+=1; 

# function to calculate 
# number of factors 
def calculateNoOFactors(n): 
	if (n == 1): 
		return 1; 
	ans = 1; 

	# stores the smallest 
	# prime number that 
	# divides n 
	dup = factor[n]; 

	# stores the count of 
	# number of times a 
	# prime number divides n. 
	c = 1; 

	# reduces to the next 
	# number after prime 
	# factorization of n 
	j = int(n / factor[n]); 

	# false when prime 
	# factorization is done 
	while (j > 1): 
		# if the same prime 
		# number is dividing 
		# n, then we increase 
		# the count 
		if (factor[j] == dup): 
			c += 1; 

		# if its a new prime factor 
		# that is factorizing n, 
		# then we again set c=1 and 
		# change dup to the new prime 
		# factor, and apply the formula 
		# explained above. 
		else: 
			dup = factor[j]; 
			ans = ans * (c + 1); 
			c = 1; 

		# prime factorizes 
		# a number 
		j = int(j / factor[j]); 

	# for the last 
	# prime factor 
	ans = ans * (c + 1); 

	return ans; 



n=int(input())

generatePrimeFactors()
ans=0
for i in range(1,n+1):
    ans+=calculateNoOFactors(i)*i
    


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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