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
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 j in range(1, N+1):
        ans += f(j, N - (N%j), j)
    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 g(n):
    return (1 + n) * n // 2

def solve():
    N = II()
    ans = 0
    for j in range(1, N+1):
        ans += g(N // j) * j
    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 solve():
    N = II()

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

    ans = 0
    for i, d in enumerate(D):
        ans = ans + i * d
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

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


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 g(i, N):
    tmp = N // i
    return int(i*tmp*(tmp+1)/2)


def main():
    N = II()
    ans = 0
    for i in range(1, N+1):
        ans += g(i, N)
    print(ans)


    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()

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):
    temp = i
    while(temp <= N):
        ans += temp
        temp += i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

s = 0
q = int(n ** .5)
for i in range(1, q+1):
	x = n // i
	s += i * (x * (x+1)) / 2
	if x**2 != n:
		y = max(n // (i+1), q)
		s += (i * (i+1) // 2) * ((x * (x+1) // 2) - (y * (y+1) // 2))

print(int(s))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

s = sum(range(1, n + 1))

for i in range(2, n+1):
  t = n // i
  # 1 + 2 + 3 + ... + t
  s += i * (1 + t) * t // 2
#  for j in range(1, n // i + 1):
#    s += i * j

print(s)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
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 list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()

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

    return r


print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        val = i
        d = n//i
        val *= d*(d+1)//2
        ans += val
        #print(i, d, val)
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
"""
    Satwik_Tiwari ;) .
    4th july , 2020  - Saturday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase


import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)


def bfs(g,st):
    visited = [-1]*(len(g))
    visited[st] = 0
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == -1):
                visited[i] = visited[s]+1
                queue.append(i)
    return visited


def dfsusingstack(v,st):
    d = deque([])
    visited = [0]*(len(v))
    d.append(st)
    new = []
    visited[st] = 1
    while(len(d) != 0):
        curr = d.pop()
        new.append(curr)
        for i in v[curr]:
            if(visited[i] == 0):
                visited[i] = 1
                d.append(i)
    return new

# 6
# 1 -1 2 3 -5 0
def solve():
    n = int(inp())
    cnt = [0]*(n+1)
    for i in range(1,n+1):
        j = 1
        while(i*j <= n):
            cnt[i*j] +=1
            j+=1
    # print(cnt[:20])
    ans = 0
    for i in range(1,n+1):
        ans += i*cnt[i]
    print(ans)


testcase(1)
# testcase(int(inp()))

Submission status: Accepted

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

ans = 0

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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())
tot = 0
for d in range(1, N+1):
    nd = N//d
    tot += (d * (nd + 1) * nd) // 2

print(tot)

Submission status: Accepted

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

Submission status: Accepted

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

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:
def generate_divisor_count_sieve(N):
    tau = [0]*(N+1)
    for d in range(1,N+1):
        for n in range(d,N+1,d):
            tau[n] += 1
    return tau
N = int(input())
tau = generate_divisor_count_sieve(N)
print(sum([n*tau[n] for n in range(1,N+1)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs  = lambda: input()
ri  = lambda: int(input())
rm  = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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 make_prime_table(N):
    sieve = list(range(N + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(N ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, N + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def f(X):
    t = []
    a = X
    while a != 1:
        if len(t) != 0 and t[-1][0] == prime_table[a]:
            t[-1][1] += 1
        else:
            t.append([prime_table[a], 1])
        a //= prime_table[a]
    result = 1
    for _, n in t:
        result *= n + 1
    return result


N = int(input())

prime_table = make_prime_table(N)
result = 0
for K in range(1, N + 1):
    result += K * f(K)
print(result)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
def s(k):
    return k*(k+1)//2

n = int(input())
ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())

answer = 0
for i in range(1, n+1):
    md = n // i

    answer += i * (md *(md+1) // 2)

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline().rstrip('\n')
    

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



N = int(input())
print(calc(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem D - Sum of Divisors

# input
N = int(input())

# initialization
count = 0

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

# output
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for k in range(1,n+1):
    d = n//k
    if d == 1:
        cnt += (k+n)*(n-k+1)//2
        break
    cnt += k*d*(d+1)//2
print(cnt)

Submission status: Accepted

Solution code:


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

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

    ans += (l[i]*i)




print(ans)

Submission status: Accepted

Solution code:
from numba import njit
import numpy as np
@njit("i8(i8,i8,i8[:])")

def f(n,ans,l):
    for i in range(2,n+1):
        for j in range(i,n+1,i):
            l[j] += 1

        ans += (l[i]*i)
    return ans

n = int(input())
l = [1]*(n+1)
l[0] = 0
ans = l[1]
l_np = np.array(l,dtype="i8")

print(f(n,ans,l_np))

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:
from numba import njit
@njit("i8(i8)")

def f(n):

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

        ans += (l[i]*i)
    return ans

n = int(input())
print(f(n))

Submission status: Accepted

Solution code:
#Osa_k法（前処理をした後、素因数分解をO(logN)でできる）

N = int(input())
sieve = [-1] * (N+1)
#prime = []
for i in range(2, N+1):#前処理（各indexについて、割れる最小の素数）
    if sieve[i] == -1:#未探索のとき
        sieve[i] = i
        #prime.append(i)#素数列挙したいとき
        for j in range(i*i, N+1, i):
            if sieve[j] == -1:
                sieve[j] = i
#print(sieve)
#print(prime)

Ans = [1] * (N+1)
for i in range(2, N+1):
    p = sieve[i]
    cur = i
    cnt = 0
    while cur > 1:
        if cur % p == 0:
            cur //= p
            cnt += 1
        else:
            break
    if i == pow(p,cnt):#iの素因数がpのみ
        Ans[i] = i*(cnt+1)
    else:
        Ans[i] = Ans[i//(p**cnt)] * Ans[p**cnt]#それ以外の時、掛算すればOK
#print(Ans)
print(sum(Ans)-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#別解思考
n = int(input())
res = 0
for i in range(1, n // 2 +1):
    res += (int(n / i) * (i + int(n / i) * i)) // 2
res += (n + n // 2 +1) * (n - n // 2 ) //2
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    nums_table = [2] * (n+1)
    ans = 0
    for i in range(1, n+1):
        nums_table[i] = 2
    nums_table[1] = 1
    for i in range(2, n//2+1):
        for j in range(2*i,n+1,i):
            nums_table[j] += 1
    for i in range(1, n+1):
        ans += i * nums_table[i]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

print(sum(d))

Submission status: Accepted

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

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:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
n = int(input())
#n, m, k = map(int, sys.stdin.readline().split())
#s = input()
#A = list(map(int, sys.stdin.readline().split()))

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

print(s)

Submission status: Accepted

Solution code:
import math
import collections
import bisect
from copy import copy


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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#D
n = int(input())

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

Submission status: Accepted

Solution code:
import numpy as np
from numba import njit


@njit('i8(i8)', cache=True)
def solve(x):
    count = np.zeros(x + 1, dtype=np.int64)
    for i in range(1, x + 1):
        for j in range(i, x + 1, i):
            count[j] += j
    return count.sum()


if __name__ == "__main__":
    x = int(input())
    print(solve(x))

Submission status: Accepted

Solution code:


def submit():
    n = int(input())
    d = [1 for _ in range(n + 1)]
    d[0] = 0

    # エラトステネスの篩風
    for i in range(2, n + 1):
        coef = 1
        while i * coef <= n:
            d[i * coef] += 1
            coef += 1

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

    print(ans)


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
N=int(input())

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

Submission status: Accepted

Solution code:
import math
def S(i):
    return ((i * (i+1)) // 2)

N = int(input())
ans = 0
sqrt_N = math.floor(math.sqrt(N))

for K in range(1, N+1, 1):
    if((N // K) < sqrt_N):
        break
    # 個別に足す
    ans += S(N // K) * K

for NdivK in range(1, sqrt_N, 1):
    # [N // K]が等しいKの区間を求める
    Kbegin = N // (NdivK + 1)
    Kend = N // NdivK
    ans += (S(NdivK) * (S(Kend) - S(Kbegin)))

print(ans)

Submission status: Accepted

Solution code:
N=int(input())

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

Submission status: Accepted

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

    ans = n * (n+1) - 1

    r = int(n // 2)
    for i in range(2, r+1):
        d = (n // i) * i
        sigma = (d * (d+i))//(2*i) - i
        ans += sigma

    return ans


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ans = (n * (n+1))//2

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

    return ans


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

A = [1] * (N+1)
for i in range(2,N+1):
  a = i
  while a < N+1:
    A[a] += 1
    a += i

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

Submission status: Accepted

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

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:
from numba import njit

n = int(input())

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

print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

input = sys.stdin.readline


def I():
    return int(input())


n = I()

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

table = [0] * (N+1)

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

Sum = 0

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

    a = (n * ((2 * i) + (n - 1) * i)) // 2

    Sum += a
    #print(a)
print(Sum)

Submission status: Accepted

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

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

def cal(i):
    s = (i + i*(n//i))*(n//i)*0.5
    return s

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

Submission status: Accepted

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

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def x(a, b):
    return a*(b*(b+1)//2)
N = int(input())
sum = 0
for i in range(1, N+1):
    sum += i*((N//i+1)*(N//i)//2)
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import time
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

K = int(input())

cnt = [0]*(K+1)
ans = 0
for k in range(1,K+1):
  i = 1
  while k*i <= K:
    cnt[k*i] += 1
    ans += k*i
    i += 1

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)