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:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
table = [False for i in range(N+1)]
def primes(n):#nまでの素数を列挙0は入れちゃダメ
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**(0.5)+1)):
        if not is_prime[i]:
            continue
        for j in range(i*2,n+1,i):
            is_prime[j] = False
    return is_prime
p = primes(N)
pr = []
for i in range(N+1):
    if p[i]:
        pr.append(i)
n = len(pr)
ans = 1
def dfs(cur_num,index,s,pre,me):
    global ans
    for i in range(index,n):
        if i == index:
            if cur_num*pr[i] <= N:
                ans += (pre*(me+2))*cur_num*pr[i]
                dfs(cur_num*pr[i],index,s+pre*(me+2),pre,me+1)
            else:
                break
        else:
            if cur_num*pr[i] <= N:
                ans += pre*(me+1)*2*cur_num*pr[i]
                dfs(cur_num*pr[i],i,s+pre*(me+1)*2,pre*(me+1),1)
            else:
                break
    return
dfs(1,0,1,1,0)
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(N):
    div = np.zeros(N+1, np.int64)
    for n in range(1, N+1):
      for m in range(n, N+1, n):
        div[m] += 1
    div *= np.arange(N + 1)
    return div.sum()

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8, ))
    cc.compile()

from my_module import main

N = int(read())
print(main(N))

Submission status: Accepted

Solution code:
n = int(input())
result = 0
for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        result += j

print(result)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    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):
                table[j] += 1
            ans += table[i] * i
        return ans

    ans = num_divisors_table(N)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")


def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []

    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1

    return prime_list


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

    table = [0] * (N + 1)
    table[0] = 0
    table[1] = 1
    prime_list = []

    for i in range(2, N + 1):
        if table[i] == 0:
            prime_list.append(i)
            table[i] = 2
            for j in range(i + i, N + 1, i):
                c = j
                cnt = 0
                while c % i == 0:
                    c //= i
                    cnt += 1
                table[j] = table[c]*(cnt+1)
    # print(table)
    ans = 0
    for i in range(N+1):
        ans += i*table[i]
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 0
for x in range(1, N+1):
  if x * x > N:
    break
  # x = y
  ans += x * x
  # x < y の 2 倍
  y_high = N//x
  ans += 2 * x * (f(y_high) - f(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*(x+1)//2
    
print(ans)

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import bisect

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 Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

N = 10**7+1

arr = [1]*N

def sieve():
    for i in range(2, N,2):
        cnt = 0
        num = i
        while num % 2 == 0:
            cnt+=1
            num = num//2
        arr[i] = arr[i]*(cnt+1)
    
    # p = 3
    for i in range(3, N, 2):
        if arr[i] == 1:
            for j in range(i, N, i):
                cnt = 0
                num = j
                while num % i == 0:
                    cnt+=1
                    num = num//i
                arr[j]  =arr[j] * (cnt+1)


sieve()
n = int(ri())

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
from math import sqrt, floor
#, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heappushpop, heapreplace
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['NET', 'DA']
############# CODE STARTS HERE #############


def sieve(x):
    a=[2]*(x+1)
    a[1]=1
    sq=floor(sqrt(x))
    for i in range(2, sq+1):
        if a[i]:
            for j in range(i*i, x+1, i):
                a[j]+=2
            a[i*i]-=1
    return a


test_case=1
while test_case:
    test_case-=1


    n=ii()
    a=sieve(n)
    c=0
    #print(a)
    for i in range(1, n+1):
        c+=i*a[i]
    print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    f = [1]*(n+1)
    ans = 1
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            f[j] += 1
        ans += i*f[i]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())

def sieve_Eratosthenes(n):
    f = [True]*(n+1)
    f[0] = False
    f[1] = False
    m = int(n**0.5+1)
    for i in range(2,m):
        if f[i]:
            for j in range(i*i,n+1, i):
                f[j] = False
    return f

def getPrimeLists(n):
    table = sieve_Eratosthenes(n)
    return [x for x in range(2,n+1) if table[x]]

#N = 10**7
ps = getPrimeLists(N)

m = [1] * (N+1)

for p in ps:
    q = p
    i = 1
    while True:
        for n in range(q,N+1,q):
            m[n] *= p * (i+1)
            m[n] //= i
        q *= p
        i += 1
        if q > N:
            break

print(sum(m)-1)

Submission status: Accepted

Solution code:
N = int(input())
out = 0
Ta = [0]*(N+1)
for i in range(1,N+1):
    Ta[i] = Ta[i-1]+i
for i in range(1,N+1):
    out += i*Ta[N//i]
print(out)

Submission status: Accepted

Solution code:
N = int(input())

total = 0
for i in range(1, N + 1):
    a = N // i
    total += (a * i + i) * a
    # if num%2:
    #     total += (N_max + i) // 2
print(int(total / 2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(n, a, d):
    return (n * (2 * a + (n - 1) * d)) // 2


n = int(input())
ans = 0
for i in range(1, n + 1):
    n_ = (n // i)
    d, a = i, i
    sm = calc(n_, a, d)
    ans += sm
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = (N*(N+1))//2

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    sqrt_intN = int(N ** 0.5 + 1)
    l = [1 if i % 2 else 2 for i in range(N+1)]
    if N == 1:
        print(1)
        return
    if N == 2:
        print(5)
        return
    ans = 5
    for i in range(3, N+1):
        ans += (l[i] + 1) * i
        t = i * 2
        while t <= N:
            l[t] += 1
            t += i
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
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 math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Factoring by trial split -- START --
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l
# Factoring by trial split --- END ---

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  n=I()
  ans=0

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

  # for i in range(1,n+1):
  #   x=1
  #   if i==1:
  #     pass
  #   else:
  #     pl=getPrimeList(i)
  #     pl=summarizeList(pl)
  #     for a,c in pl:
  #       x*=(c+1)

  #   ans+=i*x

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
n=int(input())
ans=2*(n*(n+1))//2-1
a=2
while n//a>1:
  # aを約数に持つ整数を数えて足す
  # 項数：n//a-1
  # 初項：2*a
  # 最終：n-n%a
  ans+=((n//a-1)*(2*a+n-n%a))//2
  a+=1
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:
n = int(input())
ans = 1
c = [1]*(n+1)
for i in range(2,n+1):
    for j in range(i,n+1,i):
        c[j] += 1
    ans += i*c[i]
        
print(ans)

Submission status: Accepted

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

N = INT()

cnt = [2]*(N+1)
cnt[0] = 0
cnt[1] = 1

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


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

print(sum(cnt))

Submission status: Accepted

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

Submission status: Accepted

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

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

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 findDivisors(n): 
      
    # List to store the count 
    # of divisors 
    div = [0 for i in range(n + 1)] 
      
    # For every number from 1 to n 
    for i in range(1, n + 1): 
          
        # Increase divisors count for 
        # every number divisible by i 
        for j in range(1, n + 1): 
            if j * i <= n: 
                div[i * j] += 1
            else:
              break
    return div

n=int(input())
ans=0
dp=findDivisors(n)
for i in range(len(dp)):
	ans+=(dp[i]*(i))
#print(*dp)
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:
n = int(input())

count = 0
for i in range(n):
  m = n // (i+1)
  count += (i+1)*m*(m+1)/2

print(int(count))

Submission status: Accepted

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
sieve=[-1]*(n+1)
for i in range(2,n+1):
  if sieve[i]==-1:
    sieve[i]=i
    for j in range(i*i,n+1,i):
      if sieve[j]==-1:
        sieve[j]=i

Ans=[1]*(n+1)
for i in range(2,n+1):
  p=sieve[i]
  cur=i
  ct=0
  while cur>1:
    if cur%p==0:
      cur//=p
      ct+=1
    else:
      break
  if i==pow(p,ct):
    Ans[i]=i*(ct+1)
  else:
    Ans[i]=Ans[i//(p**ct)]*Ans[p**ct]
print(sum(Ans)-1)

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    #rdivisors=[]
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
    return divs_number


def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################

def main():
    #code goes here
    x=ii()
    answer=0
    for i in range(1,x+1):
        an=x-(x%i)
        a=i
        n=an//a
        answer+=(n*(a+an))//2
    print(answer)
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
x = 0
for i in range(1,n+1):
    #ddprint(f"{i=} {n//i} {i*(n//i)}")
    m = n//i
    x += i*(m*(m+1)//2)
print(x)

Submission status: Accepted

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

    ans = 0
    l = n
    i = 1
    while l > 0:
        k = i*(i+1)//2
        l_n = n//(i+1)
        ans += k*(l*(l+1)//2-l_n*(l_n+1)//2)
        l = l_n
        i+=1
    
    print(ans)
main()

Submission status: Accepted

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

n = int(input())
ans = 0
table = [0] * (n + 1)

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
yakusu = [0] * (N + 2)
cnt = 0
for i in range(1, N+1):
    x = i
    cnt += i * (yakusu[i] + 1)
    yakusu[i] += 1
    while (True):
        x += i
        if (x <= N):
            yakusu[x] += 1
        else:
            break

print(cnt)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = list(range(N + 1))
    r = 0
    for i in range(1, N + 1):
        n = N // i
        r += i * n * (n + 1) // 2
        

    return r

print(main())

Submission status: Accepted

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc172/abc172_d
import sys
from numba import njit

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

@njit('i8(i8)', cache=True)
def f(N):
    r = 0
    for i in range(1, N+1):
        n = N // i
        r += i * n * (1 + n) // 2
    return r

def main():
    N = i2n()
    print(f(N))
    return

main()

Submission status: Accepted

Solution code:
N = int(input())

res = 0

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

Submission status: Accepted

Solution code:
N = int(input())

if N == 1:
  print(1)

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

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

  print(sum_)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(res)

Submission status: Accepted

Solution code:
N = int(input())

dp = [1] * (N+100)
dp[0] = 0
dp[1] = 1

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


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

Submission status: Accepted

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

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

dp = num_divisors_table(N)

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

print(ans)

Submission status: Accepted

Solution code:
import math

n=int(input())
 
ans=0
for x in range(1,n+1):
  mx=math.floor(n/x)
  ans+=mx*(mx+1)*x
  
print(round(ans/2))

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

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

allsum = n*(n+1)*0.5
partsum = (n//2)*(n//2+1)*0.5

#print("all",allsum)
#print("part",partsum)

ans = ans + (allsum - partsum)

print(int(ans))

Submission status: Accepted

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

N = INT()

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

divs = [1] * (N+1)

ans = 1
for i in range(2, N+1):
    if divs[i] == 1:  # prime
        k = i
        while k <= N:
            m = k
            cnt = 1
            while m % i == 0:
                cnt += 1
                m //= i
            divs[k] *= cnt
            k += i
        ans += i*2
    else:
        ans += i*divs[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
if N == 1:
    print(1)
elif N == 2:
    print(5)
elif N == 3:
    print(11)
else:
    ans = N*(N+1)-1
    for i in range(2,N//2+1):
        t = N//i
        ans += i*(t*(t+1)//2-1)
    print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import bisect

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()

    yaku = [0] * (N + 1)

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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