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 math 
def num_divisors_table(n):
  maxnum=math.floor((n + 1)/2) #3
  #table = [0 for _ in range(n+1)]
  length=n-maxnum
  aftersum=int(maxnum*length+length*(length+1)/2)
  aftersum+=(1+n)*n/2
  if n>=2:
    if n%2==0:
      aftersum+=(1+n/2)*n/2
    else:
      aftersum+=(1+(n-1)/2)*(n-1)/2

  for i in range(3, maxnum+1):
    for j in range(i, n+1, i):
      aftersum += j
      #print(i,j)
  return aftersum

N=int(input())
#Nlist,ans_1=num_divisors_table(N)
#print(Nlist)
print(int(num_divisors_table(N)))
#print(int(sum(Nlist)+ans_1))

Submission status: Accepted

Solution code:
n= int(input())
dp=[1]*n

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

Submission status: Accepted

Solution code:
n = int(input())

import math
def divisor(n):
    a = set()
    for i in range(1, math.ceil(n**0.5) + 1):
        if n % i == 0:
            a.add(i)
            a.add(n // i)
    return a
x = [0] * (n+1)
for i in range(1, n+1):
    for j in range(i, n+1, i):
        x[j] += 1
ans = 0
for i in range(n+1):
    #print(i,x[i],divisor(i))
    ans += (i * x[i])
print(ans)

Submission status: Accepted

Solution code:
n=int(input());l=int(n**.5);print(sum(m*(m+n//m)*(n//m+1-m)for m in range(1,l+1))-l*(l+1)*(2*l+1)//6)

Submission status: Accepted

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

def calc():
  n=int(input())
  table=[1]*(n+1)
  check=[False]*(n+1)
  for i in range(2,n+1):
    if check[i]==True:
      continue
    check[i]=True
    for j in range(1,n//i+1):
      check[i*j]=True
      tmp=j
      cnt=1
      while tmp%i==0:
        tmp//=i
        cnt+=1
      table[i*j]*=(i**cnt)*(cnt+1)
  print(sum(table)-1)
calc()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(sys.stdin.readline())

ans = 0

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

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

b = int(a**0.5)+1

res = 0
for i in range(1,a//2+1):
    x = a//i
    y = i*x
    z = (i+y)*x //2
    res += z
zz = (a+a//2+1)*(a-a//2)//2
res +=zz

print(res)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b

# エラトステネスの篩の篩みたいに約数の個数をどんどん作っていくのは？


def ret_eratos(N: int):
    '''エラトステネスの篩'''
    '''is_primeは約数の個数'''
    is_prime = [0] * (N + 1)
    is_prime[0] = -2  # 0と1は素数ではない
    is_prime[1] = -1
    for i in range(2, N // 2 + 1):
        for j in range(i * 2, N + 1, i):  # iの倍数は素数でない
            is_prime[j] += 1
    for i in range(N + 1):
        is_prime[i] += 2
    return is_prime


N = a_int()
eratos = ret_eratos(N)
# print(eratos)
ans = 0
for k in range(1, N + 1):
    ans += k * eratos[k]
print(ans)

# でも多分TLEだなぁ

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def primes(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]]


def main():
    N = NI()


    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
    D = num_divisors_table(N)
    ans = 0
    for i in range(1, N+1):
        ans += D[i] * i
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def gcd_cnt(n):
    sub = 0
    for i in range(1, n+1):
        kosuu = n//i
        sub+=kosuu*(2*i + (kosuu-1)*i)//2
    return sub

n = int(input())
sub = gcd_cnt(n)
print(sub)

Submission status: Accepted

Solution code:
n=int(input())
f=[2-x%2 for x in range(n+1)]
s=5
for c in range(3,n+1):
    for d in range(1,n//c+1):
        f[c*d]+=1
    s+=c*f[c]
if n==1:
    print(1)
elif n==2:
    print(5)
else:
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
sum = 0;

nn = n//2;
nnn = n-nn
if n <= 5000000:
    for i in range(1,n+1):
        x = n//i;
        sum += i*x*(x+1)//2;
else:
    for i in range(1,5000000+1):
        x = n//i;
        sum += i*x*(x+1)//2;
    sum += (n-5000000)*(5000001+n)//2;
print(sum);

Submission status: Accepted

Solution code:
from math import sqrt

n = int(input())
ans = 0
divisor = [0 for _ in range(n+1)]
for k in range(1, n+1):
    i = 1
    while 1:
        divisor[k*i] += 1
        i += 1
        if k*i > n:
            break
for i in range(1, n+1):
    ans += i * divisor[i]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
ans=0
tl=[0]*(N+1)
for i in range(1,N+1):
    t=i
    while t<=N:
        tl[t]+=1
        t+=i
for i in range(1,N+1):
    ans+=tl[i]*i
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())

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

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
def main():
    N = int(input())
    tmp = num_divisors_table(N)
    ans = 0
    for i in range(1,N+1):
        ans += i * tmp[i]

    print(ans)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
from itertools import *
s=[*accumulate(range(n+1))]
print(sum(i*s[n//i] for i in range(1,n+1)))

Submission status: Accepted

Solution code:
#!python3

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

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

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
div_table = [1]*(n+1)
div_table[0] = 0
for i in range(2, n+1):
    j = i
    while j < n+1:
        div_table[j] += 1
        j += i

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

Submission status: Accepted

Solution code:
n = int(input())

l = [1] * (n + 1)
res = 1

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

#print(l)
res = 0
for k in range(1, n + 1):
    res += k * l[k]
    
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd, sqrt
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



def prime_decomposition(n):
    table = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            table += [i]
            n //= i
        if n == 1:
            break
    if n != 1:
        table += [n]
    return table

n = I()

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




print(ans)

Submission status: Accepted

Solution code:
N = int(input())
 
sum = 0
ro = 1
for n in range(1,N+1):
    num = int(N/n)
    if num == 1:
        record = n
        break
    s = int(((1+num)*num)/2)
    sum += ro*s
    ro += 1


sum += int(((record+N)*(N-record+1))/2)
print(sum)

Submission status: Accepted

Solution code:
import math
N = int(input())
S = 0
for i in range(N):
  j = i + 1
  m = math.floor(N/j)
  S += j*(1/2)*m*(m+1)
print(int(S))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

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

    return result

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

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

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

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

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

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

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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


if __name__ == "__main__":

    main()

Submission status: Accepted

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

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:
#!/usr/bin/env python3

import sys
import math
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)



def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = [1]*n
	if n == 1:
		print(1)
		exit()
	for i in range(2, n+1):
		for j in range(i, n+1, i):
			a[j-1] += 1
	log.print(a)
	ans = 0
	for i in range(n):
		ans += a[i] * (i+1)
	print(ans)




main()

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    n = int(input())
    # index '0' is not used.
    fact = [2]*(n+1)
    fact[1] = 1

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

        for j in range(i+1, n+1):
            now = i*j
            if now <= n:
                fact[i*j] += 2
            else:
                break
    
    ans = 0
    for i in range(1, n+1):
        ans += i * fact[i]

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = [1] * (n + 1)
    ans = 1
    for i in range(2, n + 1):
        if A[i] == 1:
            m = i ** 2
            j = 2
            for a in range(i, n + 1, i):
                if a == m:
                    A[a] *= (j + 1)
                    m *= i
                    j += 1
                else:
                    count = 1
                    k = a // i
                    while k % i == 0:
                        k = k // i
                        count += 1
                    A[a] *= (count + 1)
            ans += 2 * i
        else:
            ans += A[i] * i
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
div = [1] * (n + 1)

for i in range(2, n + 1):
    cnt = 1
    while i * cnt <= n:
        div[i * cnt] += 1
        cnt += 1
print(sum([x * y for x, y in enumerate(div)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
if n==1:
    print(1)
else:
    r=1+(n*(n+1)//2-1)*2
    for i in range(2, int(n**0.5)+1):
        for j in range(i*i, n+1, i):
            if i**2!=j:
                r+=2*j
            else:
                r=r+j
    print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from collections import Counter

def main():
    N = int(input())
    if N==1:
        print(1)
        exit()
    elif N==2:
        print(5)
        exit()

    divs = [1]*(N+10)

    for i in range(2, N+1):
        max_t = N // i
        for j in range(1, max_t+1):
            val = i*j
            divs[val] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i * divs[i]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
table = [1] * (N + 1)
res = 0
for x in range(1, N + 1):
  res += table[x] * x
  for y in range(x * 2, N + 1, x): table[y] += 1
print(res)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

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


print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans=0

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

print(ans)

Submission status: Accepted

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

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())
X = num_divisors_table(N)
sum = 0
for i in range(N):
  sum += (i+1) * X[i+1]

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
M = 0
r = 0
if N>1000000:
    M = N


for i in range(min(N,1000000)):
    m = i + 1
    j = int(N/(m))
    r = r + int(m*j*(1+j)/2)

if M!=0:
    for i in range(10):
        k = int(M/(i+1))
        if k > 1000000:
            r = r + (i+1)*int((k-1000000)*(k+1000001)/2)

print(r)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    y = [0]*(n+1)
    for i in range(1,n+1):
        j = 1
        while True:
            if i*j > n:
                break
            y[i*j] += 1
            j += 1
    res = 0
    for i in range(1,n+1):
        res += i*y[i]
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
def find(a):
    return (a*(a+1))//2
n=int(input())
ans=0
for i in range(1,n+1):
    ans+=i*find(n//i)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
import math
import bisect
from collections import deque
def input():
    return sys.stdin.readline()[:-1]

n = int(input())

f = [0 for i in range(n+1)]

ans = 0
lis = [0]
for i in range(1,n+1):
    lis.append(lis[-1]+i)

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
import collections

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())
#N=10**7
#print(prime_factor(N,prime_factor_table(N)))
ans = 0
print(sum(num_divisors_table(N)))

    #num_divisors_table(N)

Submission status: Accepted

Solution code:

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


print(s)

Submission status: Accepted

Solution code:
import math
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def numdiv(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()
era = numdiv(N)
ans = 0
for i in range(1,N+1):
    ans += era[i]*i
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

def solve(N):
    dp = [2 for _ in range(N+1)]
    dp[1] = 1

    for i in range(2,int(sqrt(N)) + 1):
        for j in range(2, N//i + 1):
            if j <= int(sqrt(N)):
                dp[i * j] += 1
            else:
                dp[i * j] += 2

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

    return ans

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

    print(solve(N))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
ret = 0

for m in range(1, n+1):
    if m * m > n:
        break
    val1 = m * (m + (n//m)) * ((n//m) + 1 - m)
    ret += val1

sq = int(math.sqrt(n))
if (sq + 1) ** 2 <= n:
    sq += 1
val3 = sq * (sq + 1) * (2 * sq + 1) // 6
ret -= val3


print(ret)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
cnt = 0
for i in range(1, N + 1):
    opt = N // i
    cnt += i * (opt + 1) * opt //2
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(x)

Submission status: Accepted

Solution code:
import math
N = int(input())
number = [2]*N
ans = 1
if(N>=2):
  for i in range(2,N+1):
    ans += number[i-1]*i
    #if(i<=math.sqrt(N)):
    if(i <= int(N/2)):
      for j in range(2,N//i+1):
        number[i*j-1] += 1
print(ans)

Submission status: Accepted

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


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

main()

Submission status: Accepted

Solution code:


"""
ai             aj
bi             bj


1              2
2              1

1  how many pairs 
2
"""



import collections
n = int(raw_input())
mem = [0] * (n + 1)
mem[1] = 1
primes = [True] * (n + 1)
posprimes = []
d= 2
while( d <= n):
	if primes[d] is True:
		posprimes.append(d)
		k = 2
		while(k * d <= n):
			primes[k * d] = False
			k += 1
	d+=1
def f(k):
	if primes[k] is True:
		mem[k] = 2 if k > 1 else 1
		return mem[k]
	for pos in posprimes:
		if k % pos == 0:
			count = 0
			q = k
			while(q % pos == 0):
				q /= pos
				count += 1

			mem[k] = (count + 1) * mem[q]
			return mem[k]



s = 0
k = 1
while (k<= n):
	s += k * f(k)
	k += 1
print s




#2 4 6 8 10 12 14 16 18
#    6      12       18

Submission status: Accepted

Solution code:
from numba import njit


@njit
def solve(n: int):
    div = [1] * n  # div[n] = n + 1の約数の個数
    for i in range(2, n + 1):
        for j in range(i, n + 1, i):
            div[j - 1] += 1

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

    return ans


print(solve(int(input())))

Submission status: Accepted

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

N = int(input())
ans = 0

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

Submission status: Accepted

Solution code:
n=int(input())
sums=0
i=1
while i<=n:
    m=n//i
    sums=sums+((m+1)/2*m)*i
    i=i+1
print(int(sums))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def num_divisors_table(n):
    table = 0
    
    for i in range(1, n + 1):
        table += ((n//i +1)*(n//i )*i)/2
        
    return int(table)

N =int(input())

print(num_divisors_table(N))

Submission status: Accepted

Solution code:
N = int(input())

ans = 1
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 = ans + i*dp[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

RL = [0] * (10 ** 7 + 10)
for i in range(1, 10 ** 7 + 10):
    RL[i] = RL[i-1] + i

#print("step")

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

print(ans)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()

# n以下の整数でiで割り切れる数の総和
def sumofdivi(n,i):
    a = n//i
    b = (a*(a+1))//2*i
    return b

ans = 0
for i in range(1,n+1):
    v = sumofdivi(n,i)
    ans += v

print(ans)

Submission status: Accepted

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

N = int(input())

list = [1] * (N+1)
ans = 1
for i in range(2,N+1):
    ans += i * (list[i] + 1)
    j = i
    if i != 1:
        while j <= N:
            list[j] = list[j] + 1
            j = j + i

print(ans)

Submission status: Accepted

Solution code:
import sys


def _i(): return int(sys.stdin.readline().strip())


def main():
    n = _i()
    s = 0
    for i in range(1, n+1):
        m = n // i
        l = (m*(m+1)) // 2
        s += i*l
    return s


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

Submission status: Accepted

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

    ans = 1
    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 = ans + i*dp[i]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

import sys

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    answer=0

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

    return

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import numpy as np
def main():
  n=int(input())+1
  yueg=[0]*(n)
  for i in range(1,n):
    j=0
    while j < n:
      yueg[j]+=1
      j+=i
    yueg[i]*=i
  r=0  
#yueg=np.array(yueg)
#ka=np.arange(n)
#r=np.sum(yueg*ka)
  print(sum(yueg)-yueg[0])
main()