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

k=[0]*(n+1)
for i in range(1,n+1):
    j=i
    while j<=n:
        k[j]+=1
        j+=i
ans=0
for i in range(1,n+1):
    ans+=i*k[i]
print(ans)

Submission status: Accepted

Solution code:
from math import floor
from queue import LifoQueue


def print_sol(c, sol):
    print('Case #{}: {}'.format(c, sol))


def rd_int():
    return int(input())


def rd_str():
    return input()


def rd_str_lst():
    return input().split(' ')


def sp_str_lst():
    return list(input())


def rd_int_lst():
    return [int(i) for i in rd_str_lst()]


def sp_int_lst():
    return [int(i) for i in sp_str_lst()]


def dfs(g, i, v):
    """
    recursive post order dfs
    Args:
        g: array of graph nodes
        i: node to traverse
        v: visited array

    Returns: a post order dfs of graph g
    """
    v[i] = True
    for j in g[i]:
        if not v[j]:
            dfs(g, j, v)

    print(i)


def dfs_iter(g, i, n):
    v = [False] * n
    stack = LifoQueue()
    stack.put(i)
    while stack.not_empty:
        u = stack.get()
        v[u] = True
        print(u)
        for i in g[u]:
            if not v[i]:
                stack.put(i)


def main():
    n = rd_int()

    sol = 0
    for i in range(1, n + 1):
        ap_len = floor(n / i)
        ap_sum = (ap_len / 2) * (2 * i + (ap_len - 1) * i)
        sol += ap_sum

    print(int(sol))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

N = n1()

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

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

print(ans)

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

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)

Submission status: Accepted

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

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

    res = 0

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

if __name__ == '__main__':
    main()

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

sieve= [0]*(N+1)
sieve[0]=-1
sieve[1]=-1
for i in range(2,N+1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i*i, N+1, i):
        if sieve[j] ==0:
            sieve[j] = i
            
def G(x):
    t=[]
    a = x
    while a!=1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a],1])
        a //= sieve[a]
    result = 1
    for _,n  in t:
        result *= n+1
    return result

sum = 0
for i in range(1, N+1):
    sum += i*G(i)
print(sum)

Submission status: Accepted

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


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


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

    n = int(input())
    ans = 0

    # See: https://www.youtube.com/watch?v=v8ppNGf49Nk&feature=youtu.be
    # KeyInsight:
    # ①約数⇄倍数と言い換え
    # 1の倍数: 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
    # 2の倍数: 2, 4, 6, 8, ...
    # 3の倍数: 3, 6, ...
    # ...

    # ②1の倍数の和を基準に、等価な式変形を行う
    # 1の倍数の和は、g(x) = n * (n + 1) // 2
    # 2の倍数の和は、2 * (1, 2, 3, 4, ...)と考えることで、 2 * g(x / 2)
    # 以降、同様

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
 
s=k=kn=0;n=N
while k<n:
	k += 1
	n = N//k
	kn = k*n*(n+1)
	s += 4*kn
s -= (k+1)*kn
if n<k:
	s -= 2*kn 
print(s//4)

Submission status: Accepted

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

print(t)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

ans = 0

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

print(int(ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline
 
def main():
  n = int(input())
  ans = 0
  for i in range(1, n+1):
    res = n // i
    ans += i * res*(res+1) //2
  print(ans)

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
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 += cnt[i] * i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def sieve(n):
    # 1.9 seconds.

    # 1 and n are divisors for every n.
    is_prime = [2]*(n + 1)
    is_prime[0], is_prime[1] = 0, 0

    # is_prime holds the number of positive divisors of N. Instead of being a bool of 0/1 for prime/not prime. for example of N=24--->  is_prime[24] = 6 (1, 2, 3, 4, 6 ,24)

    for num in range(2, n+1//2):
        for mult in range(2*num, n+1, num):
            is_prime[mult] += 1
        
    ans = 1

    # i is N. elem is f(N)
    for i, elem in enumerate(is_prime[2:]):
        ans += (elem)*(i + 2)

    print(ans)

def geothermal(n):
    # Source: https://codeforces.com/blog/entry/79438
    # Let's reframe the problem by considering the total contribution each divisor makes to the answer. For any given i, i contributes K to the sum for each K from 1 to N such that K is a multiple of i.
    ans = 0
    for i in range(1, n+1):
        mult = n//i
        ans += (mult*(mult + 1)*i)//2
    print(ans)

geothermal(n)

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):
    nu = n // i
    ans += nu * (nu+1) * i // 2
print(ans)

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

n = int(input())

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
sumy=0
#nの半分より上の倍数は1個なのでそこで分ける
numhalf=int(n/2)
#nの半分までは倍数ごとに個数を求めて足していく
for i in range(numhalf):
  t=i+1
  k=int(n/t)
  sumy+=int(t*k*(k+1)/2)
#半分より上の倍数はすべて1個ずつなのでまとめて足す
sumy+=int((n+numhalf+1)*(n-numhalf)/2)
print(sumy)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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 solve(N):

    yaku = np.zeros(N + 1, np.int32)

    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]

    return ans


def main():

    N = in_n()
    print(solve(N))


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


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

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    for j in range(i+i,lim,i):
      is_p[j] +=1
  return is_p

lim=n+1
is_p=eratosthenes(lim)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

print(ans)

Submission status: Accepted

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

for i in range(1, n+1):
    a1 = i
    d = i
    nn = n // i
    ans += (nn * (2*a1 + (nn-1)*d)) // 2
    # print(i,ans,a1,nn,d)

print(ans)

Submission status: Accepted

Solution code:
from numba import jit
def _resolver(N):
    count = 0
    for j in range(1, N+1):
        for i in range(1, N+1):
            if i % j ==0:
                count += i
    #j, j*2, j*3 ,,,, j*(N//j)
    return count

#@jit("u8(u8)")
def resolver(N):
    if N == 0:
        return 0
    if N == 1:
        return 1
    
    count = 0
    #for j in range(N+1):
    #    for i in range(N+1):
    #        if i % j ==0:
    #            count += i
    #j, j*2, j*3 ,,,, j*(N//j)

    for j in range(1,N+1):
        length = N // j
        count += length*(j+(j*length)) // 2
    return count

def resolver2(N):

    import numpy as np
    J = np.arange(1, N+1, dtype=np.int64)
    length = N // J
    count = sum(length*(J+(J*length)) // 2)
    return count

def test():
    print(resolver2(10**7))
    for n in range(1, 100):
        ans1 = _resolver(n)
        ans2 = resolver2(n)
        if ans1 != ans2 or n < 11:
            print(f"n={n} ans={ans1}, {ans2}")
    print("OK")


def main():
    #test()
    N = int(input())
    ans = resolver(N)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n//2+1):
    tmp = n//(i+1)
    ans += (i+1)*tmp*(tmp+1)//2
ans += (n+(n//2+2))*(n-n//2-1)//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
divisor = [0 for _ in range(n+1)]
for i in range(1,n+1):
    j = 1
    while j*i<=n:
        divisor[j*i]+=1
        j+=1
ans = 0
for ix,val in enumerate(divisor):
    ans += ix*val
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# O(N) 

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

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

print(ans)

Submission status: Accepted

Solution code:
from numba import njit

@njit
def func(N):
  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]
  return ans

N = int(input())
ans = func(N)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    f(K) = number of divisors of K
    sum(K*f(K)), K=1...N
    f(1) = 1, f(2) = 2, f(3) = 2, f(4) = 3
    1 <= N <= 10**7

    36 = 1, 2, 3, 4, 6, 9, 12, 18, 36
    f(36) = 9
    """
    N = read_int()
    counter = [1]*(N+1)
    for divisor in range(2, N+1):
        for step in range(divisor, N+1, divisor):
            counter[step] += 1
    return sum(k*counter[k] for k in range(1, N+1))


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import math

n = int(input())
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

s=k=kn=0;n=N
while k<n:
	k += 1
	n = N//k
	kn = k*n*(n+1)
	s += 4*kn
s -= (k+1)*kn
if n<k:
	s -= 2*kn 
print(s//4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

f = [0] * (n+1)

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=np.arange(1,n+1)
print((n//a*(a+n//a*a)//2).sum())

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=np.arange(1,n+1)
b=n//a*a
c=n//a
print((c*(a+b)//2).sum())

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())

n_min=np.arange(1,n+1,dtype=np.int64)
n_max=n//n_min*n_min
kousu=n//n_min

print((kousu*(n_min+n_max)//2).sum())

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n=int(readline())

    ans=0
    n_min=np.arange(1,n+1,dtype=np.int64)
    n_max=n//n_min*n_min
    kousu=n//n_min
    ans=(kousu*(n_min+n_max)//2).sum()

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())

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

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

a = [0 for _ in range(N + 1)]

for i in range(1, N + 1):
    temp = i
    while(temp <= N):
        a[temp] += 1
        temp += i
        
ans = 0
for i in range(1, N + 1):
    ans += i * a[i]
print(ans)

Submission status: Accepted

Solution code:
import collections as cc
import itertools as it
import bisect as bi
I=lambda:list(map(int,input().split()))
n,=I()
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())
print(sum((i * (n // i) * (n // i + 1) // 2) for i in range(1, n + 1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Sum of Divisors
import numpy as np
N = int(input())

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

print(int(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# O(NlogN) 
# PyPy3ならAC, Python3ではTLE

n = int(input())

div = [0 for _ in range(n+1)]
for i in range(1, n+1):
    ti = i 
    while ti <= n:
        div[ti] += 1 
        ti += i
ans = 0 
for i in range(1, n+1):
    ans += i*div[i]
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:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def f(l, r, kousa=1):
    n = (r - l) // kousa
    return (r + l) * (n + 1) // 2

def solve():
    N = II()
    # N = 10

    ans = 0
    for i in range(1, N+1):
        mx = i * (N // i)
        # print(i, mx)
        if i == mx:
            ans = ans + f(i, N, 1)
            break
            # mx = i
        # print(i, mx, f(i, mx, i))
        ans = ans + f(i, mx, i)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def f(l, r, kousa=1):
    n = (r - l) // kousa
    return (r + l) * (n + 1) // 2

def solve():
    N = II()

    ans = 0
    for i in range(1, N+1):
        mx = i * (N // i)
        if mx == 0: mx = i
        # print(i, mx, f(i, mx, i))
        ans = ans + f(i, mx, i)

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


N = int(input())

# 正の整数iに対して、iの倍数でありN以下であるものの総和をg(i)とおくと、
# 求めたい\sum_{K=1}^{N} K * f(K)は、
# \sum_{K=1}^{N} K * f(K) = \sum_{K=1}^{N} g(K)
# で与えられる。
# ここで、kをN/i以下の最大の整数とおくと、g(i)は、
# g(i) = i + 2 * i + 3 * i + ... + k * i = (1 + 2 + 3 + ... + k) * i
# = k * (k + 1) * i / 2 (等差数列の和)
# で与えられる。


def g(i):
    k = N // i
    return k * (k + 1) * i // 2


res = 0
for i in range(1, N+1):
    res += g(i)
print(res)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()

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

    ans = 0
    i = 0
    for t in T:
        ans = ans + i * t
        i = i + 1

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

n = int(input())

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

print(ans)

Submission status: Accepted

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

n = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
n = int(input())
ans = 0

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

Submission status: Accepted

Solution code:
import sys

if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(1, n + 1):
        h = n // i
        ans += i * ((h * (h + 1)) // 2)
    print(ans)
    return




n = RN()
solve()

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for n in range(1,N+1):
    max_n = N//n*n
    min_n = n
    cnt = (max_n-min_n)//n + 1
    temp = (max_n + min_n) * cnt // 2
    ans += temp
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
n=int(input())
s=0
a=[1]
for i in range(n-1):
    a.append(a[i]+(i+2))
for i in range(1,n+1):
    s+=i*a[(n//i)-1]
print(s)

Submission status: Accepted

Solution code:
## necessary imports
import sys
input = sys.stdin.readline
#from math import ceil, floor, factorial;

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

## gcd function
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k 
    res = 1
    for i in range(k): 
        res = res * (n - i) 
        res = res / (i + 1) 
    return int(res) 

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
    hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e7 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve() 
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

def summ(a):
    an = (n // a) * a;
    x = ((an - a ) // a )+ 1
    sn = (x * (a + an))//2;
    return sn;

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

Submission status: Accepted

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