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:
def f(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
        table[i] *= i
    
    return table

def main():
    N = int(input())
    ans = 0
    print(sum(f(N)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

M = [2 for k in range(N+1)]
M[0] = 0
M[1] = 1

for k in range(2, N+1):
    if N//k >1:
        for j in range(k, N+1-k, k):
            M[k+j] +=1

ans = 0
for k in range(1, N+1):
    ans+=(k)*M[k]
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 = 0
memo = [0] * (N + 1)
for i in range(1,N+1):
    n = N // i
    if memo[n] == 0:
        tmp = n * (n + 1) // 2
        ans += tmp * i
        memo[n] = tmp
    else:
        ans += memo[n] * i
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

n = int(input())

is_prime = [1]*(n + 1)
is_prime[0], is_prime[1] = 0, 0

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

ans = 1
for i, elem in enumerate(is_prime[2:]):
    ans += (elem + 1)*(i + 2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

S = num_divisors_table(N)

ans = 0

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

Submission status: Accepted

Solution code:
def resolve():
  N = int(input())
 
  table = [1]*(N+1)
  for i in range(2, N+1):
    n = i
    while n <= N:
      table[n] += 1
      n += i
 
  ans = 0
  for i in range(1, N+1):
    ans += i*table[i]
 
  print(ans)
 

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
n=int(input())
ans=0
for i in range(1,n+1):
    num=0
    while num<=n:
        num+=i
        if (num>n):
            break
        ans+=num
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
dp = [1] * (N+1)#約数個数テーブル
def primes(n):#nまでの素数を列挙
    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 [i for i in range(n+1) if is_prime[i]]
li_p = primes(N)
for i in li_p:
    cnt = 1
    I = i
    while i <= N:
        tmp = cnt
        cnt += 1
        for j in range(i, N+1, i):
            dp[j] //= tmp
            dp[j] *= cnt
        i *= I
ans = 0
for i in range(1, N+1):
    ans += i*dp[i]
print(ans)

Submission status: Accepted

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


def solve(N: int):
    ns = [0]*N
    for i in range(1,N+1):
        for k in range(1,N//i+1):
            ns[i*k-1] += i*k
    print(sum(ns)) 
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def dt(n):
  table = [0] * (n + 1)
  r = 0
    
  for i in range(1, n + 1):
    for j in range(i, n + 1, i):
      table[j] += 1
    
  for i in range(1,n+1):
    r += i*table[i]
    
  return r

N = int(input())
print(dt(N))

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

Solution code:
n=int(input())
dp=[1]*((10**7)+100)
ans=1
for num in range(2,n+1):
  for i in range(num,(10**7)+1,num):
    dp[i]+=1
  ans+=dp[num]*num
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = [2] * n
l[0] = 1
for i in range(1, n):
    for j in range(i, n, i + 1):
        if j == i:continue
        l[j] += 1
cnt = 0
for i in range(n):
    cnt = cnt + (i + 1) * l[i]
print(cnt)

Submission status: Accepted

Solution code:
import sys

from numba import njit

input = sys.stdin.readline


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


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

    table = num_divisors_table(N)

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())


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

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

    return table


# li = np.array(num_divisors_table(N))
# k = np.arange(N + 1)

li = num_divisors_table(N)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#関数リスト
import sys
import math
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

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

result = 0
for i, k in enumerate(table):
    result += i * k

print(result)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
ans=0
for i in range(1,n+1):
    x=n//i
    ans+=(i+x*i)*x//2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans_tmp = sum(range(n+1)) * 2 -1

from itertools import accumulate
sum_list = list(accumulate(range(1, n)))

ans_tmp_2 = 0

for i in range(2, n+1//2+1):
    if n // i > 1:
        count_tmp = n // i
        ans_tmp_2 += i * sum_list[count_tmp - 1] - i

print(ans_tmp + ans_tmp_2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC172-D

N=int(input())
yaku=[0]+[1]*N

for i in range(2,N+1):
    t=N//i
    for j in range(1,t+1):
        #print(i,j)
        yaku[i*j] +=1
ans=0
for i in range(1,N+1):
    ans += i*yaku[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
l = [0] * (N + 1)
s = 0
for i in range(1,N + 1):
    d = N // i
    n = 0
    for j in range(1,d + 1):
        n += i
        l[n] += 1
    s += l[i] * i
print(s)

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

cnt = 0
for i in range(1, int(math.sqrt(N)+1)):
    sub = N//i
    cnt += (sub-i+1)*(sub+i)*i - i**2  # 約数の対となるペアも考慮するが平方根だけ別なので除外
cnt = int(cnt)
print(cnt)

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

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class Sieve:
    def __init__(self, n):
        self.plist = [2]  # n以下の素数のリスト
        min_prime_factor = [2, 0] * (n // 2 + 5)
        for x in range(3, n + 1, 2):
            if min_prime_factor[x] == 0:
                min_prime_factor[x] = x
                self.plist.append(x)
                if x ** 2 > n: continue
                for y in range(x ** 2, n + 5, 2 * x):
                    if min_prime_factor[y] == 0:
                        min_prime_factor[y] = x
        self.min_prime_factor = min_prime_factor

    def isprime(self, x):
        return self.min_prime_factor[x] == x

    # これが素因数分解(prime factorization)
    def pfct(self, x):
        pp, ee = [], []
        while x > 1:
            mpf = self.min_prime_factor[x]
            if pp and mpf == pp[-1]:
                ee[-1] += 1
            else:
                pp.append(mpf)
                ee.append(1)
            x //= mpf
        return ee

def main():
    sv=Sieve(10**7+5)
    n=II()
    ans=0
    for a in range(1,n+1):
        f=1
        for e in sv.pfct(a):
            f*=e+1
        ans+=a*f
    print(ans)

main()

Submission status: Accepted

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

    l = [1] * n

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

    for i in range(n):
        l[i] *= (i+1) 
    print(sum(l))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
MAX = int(input())
MAX+=1
factor = [0]*(MAX + 1); 
def generatePrimeFactors(): 
	factor[1] = 1;
	for i in range(2,MAX): 
		factor[i] = i; 
	for i in range(4,MAX,2): 
		factor[i] = 2; 

	i = 3; 
	while(i * i < MAX): 
		if (factor[i] == i): 
			j = i * i; 
			while(j < MAX): 
				if (factor[j] == j): 
					factor[j] = i; 
				j += i; 
		i+=1; 

def ca(n): 
	if (n == 1): 
		return 1; 
	ans = 1; 
	dup = factor[n]; 
	c = 1; 
	j = int(n / factor[n]); 
	while (j > 1): 
		if (factor[j] == dup): 
			c += 1; 
		else: 
			dup = factor[j]; 
			ans = ans * (c + 1); 
			c = 1; 
		j = int(j / factor[j]); 

	ans = ans * (c + 1); 
	return ans; 
generatePrimeFactors() 
r=1
for i in range(2,MAX):
    r+=i*ca(i)
print(r)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest


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

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

    return table

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

    ans = num_divisors_table(n)

    print(sum([i * a for i, a in enumerate(ans)]))



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4"""
        output = """23"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100"""
        output = """26879"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10000000"""
        output = """838627288460105"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = [2 for i in range(10 ** 7 + 1)]
A[1] = 1
for i in range(2, 10 ** 7 + 1):
    for j in range(2*i, 10 ** 7 + 1, i):
        A[j] +=1

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

Submission status: Accepted

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

n = int(input())
eras = num_divisors_table(n)
  
print(sum(eras))

Submission status: Accepted

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

def sumOfSeries(a,s,e):
    n = (e-a)//s+1
    return n*(a+e)//2

def solve(N: int):
    s = 0
    for i in range(1,N+1):
        # biggest N divided by i
        e = N - N % i
        s += sumOfSeries(i,i,e)
    print(s)
    return



# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())

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

Submission status: Accepted

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

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())


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


table = num_divisors_table(N)

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [1]*(N+1)
    A[0] = 0

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
n = int(input())
divs = [1] * (n+1)
for i in range(2,n+1):
    if divs[i] != 1:continue
    for x in range(n//i,0,-1):
        cnt = 1
        while x * i**cnt < n+1:
            ind = x * (i ** cnt)
            divs[ind] = divs[x]*(cnt+1)
            cnt += 1
xs = divs[1:]
ans = 0
for i,x in enumerate(xs):
    ans += (i+1)*x
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

n = int(input())

s = 0

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

print(s)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
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 print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def divisor(n):
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


def sum_arr(a, d, n):
    return (n * (2 * a + (n - 1) * d)) // 2

def divisor_sum(n):
    s = 0
    for i in range(1, n + 1):
        cnt = n // i
        # print(i, cnt, sum_arr(i, i, cnt))
        nxt = sum_arr(i, i, cnt)
        if nxt == 0:
            s += i
        else:
            s += nxt
    return s


def main():
    N = I()

    print(divisor_sum(N))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = int(input())
t = num_divisors_table(n)

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

Submission status: Accepted

Solution code:
n=int(input())
from math import sqrt,floor
x=floor(sqrt(n))
print(sum(m*(n//m+m)*(n//m+1-m) for m in range(1,floor(sqrt(n))+1))  -x*(x+1)*(2*x+1)//6)

Submission status: Accepted

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

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

main()

Submission status: Accepted

Solution code:
def num_divisors_table(n):
    table = [0] * (n + 1)

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

    return table




def main():
    n = int(input())
    tmp = num_divisors_table(n + 2)
    ans = 0
    for i in range(1, n + 1):
        ans += tmp[i]*i
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def main():
  N = int(input())
  d = [1] * (N)
  ans = 0

  for i in range(2, N+1):
    f = i

    while True:
      d[f - 1] += 1
      f += i

      if(f > N):
        break

  for K in range(1, N+1):
    ans += K * d[K-1]

  print(ans)

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
def num_divisors_table(n):
    table = [0] * (n + 1)

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

    return table
N = int(input())
table = num_divisors_table(N)
ans = 0
for i in range(1,N+1):
    ans += i*table[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = 1
b = [0]*(n+1)
for i in range(2, int(n**(1/2))+1):
    for j in range(2, int(n/i)+1):
        if i <= j:
            b[i*j] += 1
for i in range(2, n+1):
    if int(i**(1/2))**2 == i:
        a += i*(b[i]*2+1)
    else:
        a += i*(b[i]*2+2)
print(a)

Submission status: Accepted

Solution code:
from numba import njit

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

n = int(input())
N = -(-n//2)
ans = loop(n)
ans -= N * (N+1) //2
ans += n * (n+1) //2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#http://sucrose.hatenablog.com/entry/2016/11/06/234635
n = int(input())

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

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

    return table

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

Submission status: Accepted

Solution code:
import math
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table
    
  
n = int(input())

t = num_divisors_table(n)

ans = 0
for i, j in enumerate(t):
  ans += i * j
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

temp = [1 for i in range(n + 1)]
ans = 1
for i in range(2, n + 1):
    temp[i] += 1
    ans += i * temp[i]
    count = 2
    while i * count <= n:
        temp[i * count] += 1
        count += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()

    # def tousa(a, d, x):
    #     return x * (2 * a + (x - 1) * d) // 2

    # 約数を列挙　n=10^12までいける
    ans = 0
    for i in range(1, n + 1):
        ans += (n // i) * (2 * i + (n // i - 1) * i) // 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    return N,


@njit
def f(n):
    """
    約数の個数を求める
    """
    ndivs = np.ones((n+1), dtype=np.int32)
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            ndivs[j] += 1
    return ndivs


@njit
def solve(N):
    fn = f(N)
    ans = 0
    for k in range(1, N+1):
        ans += k * fn[k]
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N = int(input())

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def LI():return list(map(int,input().split()))

n=int(input())

def main(n):
    ans=0
    from math import floor
    
    def f(n):
        return n*(n+1)*(2*n+1)//6
        
    for m in range(1,floor(n**0.5)+1):
        tmp=m*(m+floor(n/m))*(floor(n/m)+1-m)
        ans+=tmp
        
    return (ans-f(floor(n**0.5)))

print(main(n))

Submission status: Accepted

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


N = INT()


# DP = [1] * (N+1)

# ans = 1
# for i in range(2, N+1):
#     for j in range(i, N+1):
#         if j % i == 0:
#             DP[j] += 1
#     ans += i*DP[j]
# print(ans)

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

Submission status: Accepted

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


N = int(input())
ans = 0
L = num_divisors_table(N)[1:]

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

Submission status: Accepted

Solution code:
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in xrange(1, n + 1):
        for j in xrange(i, n + 1, i):
            table[j] += 1
    
    return table
  
n = int(input())  
a =  num_divisors_table(n)
ans = 0
for i in range(n+1):
  ans += i*a[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = 0

t = N // 2

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

ans += (t+1 + N) * (N-t)

print(ans // 2)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    nums = [2] * (N+1)


    # nums[1] = 2
    # nums[1]
    ans = 1
    # for i in range(2,int(N**0.5)+1):
    for i in range(2,N+1):
        # nums[i] += 1
        ans += i * nums[i]
        tmp_i = i * 2
        while tmp_i<= N:
            nums[tmp_i] += 1
            tmp_i += i
            # print(nums[tmp_i],tmp_i)


    # print(nums)
    print(ans)





main()

Submission status: Accepted

Solution code:

def eratos(N):
    isprime = [1 for i in range(N+1)]
    for i in range(2, N+1):
        j = i
        while j <= N:
            isprime[j] += 1
            j = j + i
    return isprime        

N = int(input())

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

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
import bisect

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    s = sum(i*(N//i)*(N//i+1)//2 for i in range(1, N+1))
    print(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
f=[1]*(10**7+1)
f[0]=0
for i in range(2,n+1):
  for j in range(i,n+1,i):
    f[j]+=1
ans=0
for i in range(1,n+1):
  ans+=i*f[i]
print(ans)