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: Time Limit Exceeded

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

class Factorization:	
	def __init__(self):
		# privateなインスタンス変数を作成
		self.__factors = dict()
		self.__n = 0
	
	
	def get_factors(self, n):
		# [summary] 素因数分解した結果を、辞書([素因数, 指数]...)で返す
		self.__factors.clear()
		self.__n = n
		
		if n < 2:
			# 2より小さい数の場合、素因数分解できない
			return { n:1 }
		else:
			self.__factorization()
			
			return self.__factors
	
	
	def get_divisors(self, n):
		# [summary] 約数をリストに列挙
		self.__factors.clear()
		self.__n = n
		
		if n < 2:
			return [1]
		else:
			self.__factorization()
			divisors = [1]
			
			for k, v in self.__factors.items():
				import copy
				copy_ = copy.deepcopy(divisors)
								
				for i in range(1, v + 1):
					for c in copy_:
						divisors.append(c * (k ** i))
			
			return divisors

				
	def count_divisors(self, n):
		# [summary] 約数の個数を返す
		self.__factors.clear()
		self.__n = n
		
		if n < 2:
			return 1
		else:
			self.__factorization()
			count = 1
			
			for v in self.__factors.values():
				count *= v + 1
			
			return count
	

	def	__factorization(self):
		# [summary]素因数分解した結果を、インスタンス変数に格納
		
		# 2,3,5で、割れなくなるまで割り続ける
		# (末尾に2,3,5のつく数は素数でないことが明白なので
		# 後続の処理で素数のリストに入れないように、先に処理する)
		self.__divide_with(2)
		self.__divide_with(3)
		self.__divide_with(5)
			
		# 平方根以下の素数で総当たりで試し割りする
		# (実際は、素数らしき数)
		import math
		sqrt_ = math.floor(math.sqrt(self.__n))
			
		primes = [7, 11, 13, 17, 19, 23, 29, 31]
		i = 0
		is_break = False
			
		while self.__n > 1:
			for p in primes:
				if p + i <= sqrt_:
					self.__divide_with(p + i)
				else:
					# 試し割りする数が平方根を超えたら、ループを抜ける
					is_break = True
						
					# 1が素因数に追加されることを防止
					if self.__n > 1:
						self.__factors.setdefault(self.__n, 1)
				
			if is_break:
				break
			else:
				i += 30
	
	
	def __divide_with(self, d):
		count = 0
		
		while self.__n % d == 0:
			self.__n //= d
			count += 1
		
		if count > 0:
			self.__factors.setdefault(d, count)


# D - Sum of Divisors
n = int(input())
lib = Factorization()
ans = 0

for i in range(1, n + 1):
	count = lib.count_divisors(i)
	ans += i * count

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())

def count(n):
  num = 0
  sqrt_n = math.sqrt(n)
  for i in range(1, math.floor(sqrt_n)+1):
    if n % i == 0:
      num += 2
  if sqrt_n.is_integer():
    num -= 1
  return num
  
ans = 0
for k in range(1, n+1):
  ans += k * count(k)
  
print(ans)

Submission status: Time Limit Exceeded

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

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

l = [0]
for i in range(1, N+1):
    l.append(make_divisors(i))



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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def f(x):
    sum = 0
    a = [1]*(x+1)
    for k in range(2, x+1):
        i = k
        while i<=x:
            a[i]+=1
            i+=k
    for i in range(1, x+1):
        sum+=i*a[i]
    return sum
n = int(input())
print(f(n))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

# 各Kに対する約数の個数を出す

l = [0]*(N+1)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

table = [0] * (N+1)

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def div(k):
    i = 1
    ans = 0
    while i**2 <= k:
        if k%i == 0:
            ans += 2
        if i**2 == k:
            ans -= 1
        i += 1
    return ans

an = 0
for i in range(1, n+1):
    an += i*div(i)

print(an)

Submission status: Time Limit Exceeded

Solution code:
import math
"""n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=min("""
n=int(input())
sum=0
for i in range(1,n+1):
  count=0
  for j in range(1,int(math.sqrt(i))+1):
    if i%j==0:
      count=count+1
      if i%(i//j)==0 and (i//j)!=1 and (i//j)!=j:
        count=count+1
  #print(sum,i,count)
  sum=sum+i*count
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        if i % j == 0:
            ans += i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
def f(x):
    yakusu = 0
    for i in range(1,x+1):
        if x % i == 0:
            yakusu += 1
    return yakusu
ans = 0
for i in range (1,n+1):
    ans += i*f(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0
for K in range(1, N + 1):
    f = 0
    for i in range(1, K + 1):
        if i * i > K:
            break
        if i * i == K:
            f += 1
        elif K % i == 0:
            f += 2
    ans += K * f
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import time

N=int(input())

sieve= [0]*(N+1)
sieve[0]=-1
sieve[1]=-1
for i in range(2,N+1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i*i, N+1, i):
        if sieve[j] ==0:
            sieve[j] = i

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

ans = 0

for i in range(1, N+1):
	ans += np.sum(np.arange(i, N+1, i))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

base = np.arange(1, N+1)
ans = np.sum(base)

for i in range(2, N+1):
	ans += np.sum(base[base%i == 0])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def f(n):
  if n == 1 or n == 2:
    return n
  count = 2
  for i in range(2, n):
    if n % i == 0:
      count += 1
  return count

n = int(input())
answer = 0
for i in range(1, n + 1):
  answer += i * f(i)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
#import sympy


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]

n=int(input())
t=0
for i in range(1,n+1):
    t=t+(len(make_divisors(i))*i)

print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1,n+1):
    k=0
    for j in range(1,int(math.sqrt(i))+1):
        if i%j==0:
            k+=1
            if j!=i//j:
                k+=1

    t+=i*k

print(t)

Submission status: Time Limit Exceeded

Solution code:
def divisor(n):
  for i in range(n):
    x = len([i for i in range(1,n+1) if not n % i])
  return x

def sums():
    t=int(input())
    sum = 0
    for i in range(1,t+1):
        sum += i*divisor(i)
    print (sum)

sums()

Submission status: Time Limit Exceeded

Solution code:
b=int(input())
def divisor(n):
  for i in range(n):
    x = len([i for i in range(1,n+1) if not n % i])
  return x

def sums(t):
    sum = 0
    for i in range(1,t+1):
        sum += i*divisor(i)
    print (sum)
sums(b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def func(x):
  divisors = []
  for i in range(1, int(x**0.5)+1):
    if x % i == 0:
      divisors.append(i)
      if i != x // i:
        divisors.append(x//i)
  return len(divisors)

res = 0
for i in range(n):
  res += (i+1) * func(i+1)
print(res)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
sumy=0
for i in range(n):
  t=i+1
  k=int(n/t)
  sumy+=int(t*k*(k+1)/2)
print(sumy)

Submission status: Time Limit Exceeded

Solution code:
b=int(input())
def divisor(n):       
    hh = [1] * (n + 1);       
    p = 2; 
    while((p * p) < n): 
        if (hh[p] == 1): 
            for i in range((p * 2), n, p): 
                hh[i] = 0; 
        p += 1;   
    total = 1; 
    for p in range(2, n + 1): 
        if (hh[p] == 1):            
            count = 0; 
            if (n % p == 0): 
                while (n % p == 0): 
                    n = int(n / p); 
                    count += 1; 
                total *= (count + 1);                   
    return total; 
sum = 0
for i in range(1,b+1):
    sum += i*divisor(i)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
b=int(input())
def divisor(n):
  for i in range(n):
    x = len([i for i in range(1,n+1) if not n % i])
  return x
sum = 0
for i in range(1,b+1):
    sum += i*divisor(i)
print (sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0
for j in range(1, N+1):
    for i in range(1, N+1):
        if i % j == 0:
            ans += i
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from numba import njit

@njit
def func(N):
  dp = [1 for _ in range(N+1)]
  for i in range(2,N+1):
    for j in range(i, N+1, i):
      dp[j] += 1
  return dp

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    nums = [1] * (N + 1)
    s = 0
    for i in range(2, N+1):
        tmp = i
        while tmp <= N:
            nums[tmp] += 1
            tmp += i
    for i in range(1, N+1):
        s += i * nums[i]
    print(s)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
#答え
sumy=0
#約数の個数を各値ごとにリストに入れる
cnt1=[]
#各値ごとの約数の個数
cnt2=0
for i in range(n+1):
  for j in range(i):
#0で割るのを防ぐ
    k=j+1
#商が割る数より小さいときは二重に数えることになるので省く
    if i/k<k:
      break
    else:
#約数であるかを確認
      if i%k==0:
        if k==i/k:
          cnt2+=1
#計算量を減らすためにペアで数える(商と割る数)
        else:
          cnt2+=2
  cnt1.append(cnt2)
#cntを初期化
  cnt2=0    
  sumy+=cnt1[i]*i
print(sumy)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
#答え
sumy=0
#約数の個数を各値ごとにリストに入れる
cnt1=[]
#各値ごとの約数の個数
cnt2=0
for i in range(n+1):
  for j in range(i):
#0で割るのを防ぐ
    k=j+1
#商が割る数より小さいときは二重に数えることになるので省く
    if i/k<k:
      continue
    else:
#約数であるかを確認
      if i%k==0:
        if k==i/k:
          cnt2+=1
#計算量を減らすためにペアで数える(商と割る数)
        else:
          cnt2+=2
  cnt1.append(cnt2)
#cntを初期化
  cnt2=0    
  sumy+=cnt1[i]*i
print(sumy)

Submission status: Time Limit Exceeded

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

a = int(input())
ans = 0

for j in range(1, a+1):
    for i in range(1, a+1):
        if i % j == 0:
            ans += i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

f = [1]*(N+1)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
int_list = [0 for _ in range(N+1)]
ans = 0
for i in range(1, N+1):
    for j in range(i, N+1, i):
        int_list[j] += 1
for i, cnt in enumerate(int_list): ans += i*cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from numba import jit

@jit
def num_divisors_table(n):
    table = [0 for _ in range(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())

f = num_divisors_table(N)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def num_divisors_table(n):
    table = [0 for _ in range(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())

f = num_divisors_table(N)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x=0
for i in range(1,n+1):
    ans = 0
    for j in range(1,n+1):
        if i%j==0:
            ans+=1
    x += ans*i
print(x)

Submission status: Time Limit Exceeded

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

n = int(input())

div = [0 for _ in range(n+1)]
for i in range(1, n+1):
    ti = i 
    while True:
        if ti > n:
            break
        div[ti] += 1 
        ti += i
ans = 0 
for i in range(1, n+1):
    ans += i*div[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import math


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


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]]


N = z()
ans = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        if (i % j == 0):
            ans += i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def make_divisor(n):
  cnt = 0
  for i in range(1,n+1):
    for j in range(1,i+1):
      if i%j == 0: cnt += i
  return cnt

print(make_divisor(n))

Submission status: Time Limit Exceeded

Solution code:
# (1,2,3,4,5..,N) + (1,2,3,4,...,N/2) * 2 + (1,2,...,N/3) * 3 + ...+(1,) * N
# 累積和を使うことでO(1)でそれぞれの計算をする．N回ループをするので，合計O(N)の計算量で終了する

N = int(input())

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

ans = 0
for i in range(1,N+1):
    ind = int(N/i)
    ans += S[ind] * i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def make_divisor(n):
  cnt = 0
  l,u = [],[]
  i = 1
  while i*i <= n:
    q, mod = divmod(n, i)
    if mod == 0:
      cnt += 1
      if i != q:
        cnt += 1
    i += 1
  return cnt * n

ans =sum([make_divisor(x) for x in range(1,n+1)])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def make_divisor(n):
  l,u = [],[]
  i = 1
  while i*i <= n:
    q, mod = divmod(n, i)
    if mod == 0:
      l.append(i)
      if i != q:
        u.append(q)
    i += 1
  return len(l + u) * n

ans =sum([make_divisor(x) for x in range(1,n+1)])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def make_divisor(n):
  l,u = [],[]
  i = 1
  while i*i <= n:
    q, mod = divmod(n, i)
    if mod == 0:
      l.append(i)
      if i != q:
        u.append(q)
    i += 1
  return len(l + u)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    M = [0]*(N+1)
    for i in range(1,N+1):
        for j in range(i, N+1, i):
            M[j] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i * M[i]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0
for a in range(1,N+1):
  i = 1
  while i*i <= a:
    if a%i == 0:
      ans += 2*a
    i += 1
  if (i-1)*(i-1) == a:
    ans -= a


  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ans = 0
# kaito
# for i in range(N+1):
#     for j in range(N+1):
#         if i % j == 0:
#             ans += 1

# print(ans)

# teian1
# F = [0]*(N+1)#約数の個数を入れるリスト
# for i in range(1,N+1):
#     for j in range(1,N+1):
#         if j%i==0:
#             F[j]+=1 #jの倍数のところ（約数を）インクリメンとしていく
#     ans += i*F[i]
# #print(F)

#kaitou
for i in range(1,N+1):
    for j in range(1,N+1):
        if i%j==0:
            ans+=i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def divic(n):
    i = 1
    c = 0
    while i*i <= n:
        if n % i == 0:
            c += 2
        i += 1
    if (i-1)*(i-1) == n:
    	c -= 1
    return c

a = int(input())
ans = 0
for i in range(1,a+1):
  ans += i*divic(i)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
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 len(lower_divisors + upper_divisors[::-1])
cnt = 0
for m in range(1,n+1):
  cnt += m*make_divisors(m)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

def div(x):
    i=1
    d=0
    while i <= x:
        if x % i ==0:
            d += 1
        i += 1
    return d

ans=0
k = 1
while k <= n:
    j = k*div(k)
    ans += j
    k += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def SieveOfEratosthenes(n, prime,primesquare, a):
    for i in range(2,n+1): 
        prime[i] = True
    for i in range((n * n + 1)+1): 
        primesquare[i] = False
    prime[1] = False
    p = 2
    while(p * p <= n):
        if (prime[p] == True):
            i = p * 2 
            while(i <= n): 
                prime[i] = False
                i += p 
        p+=1
      
  
    j = 0
    for p in range(2,n+1):  
        if (prime[p]==True):  
            a[j] = p 
            primesquare[p * p] = True
            j+=1
def countDivisors(n):
    if (n == 1): 
        return 1
  
    prime = [False]*(n + 2) 
    primesquare = [False]*(n * n + 2) 
    a = [0]*n 
    SieveOfEratosthenes(n, prime, primesquare, a) 
    ans = 1
    i=0
    while(1): 
        if(a[i] * a[i] * a[i] > n): 
            break
        cnt = 1
        while (n % a[i] == 0): 
            n = n / a[i] 
            cnt = cnt + 1 
        ans = ans * cnt 
        i+=1 
    n=int(n) 
    if (prime[n]==True): 
        ans = ans * 2
    elif (primesquare[n]==True): 
        ans = ans * 3
    elif (n != 1): 
        ans = ans * 4
  
    return ans 
n=int(input())
s=0 
for j in range(1,n+1):
    s+=(j*countDivisors(j))
print(s)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import time

N=int(input())

sum=0
for j in range(1,N+1):
    Y=int(N/j)
    sum+=int((Y*(Y+1)*j)/2)

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
## necessary imports
import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1;
	return x;

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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


## SIEVE ON
n = int(input()); ans = 0;
for i in range(1, n+1):
    fct = factoriazation(i); this = 1;
    for k in fct:
        this *= (fct[k] + 1);
    ans += i * this;
print(ans);

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline
sys.setrecursionlimit(10**6)
########################################
mxn =  10**7
divs = [0]*(mxn + 11)
for i in range(1,mxn+1):
	for j in range(0, mxn+1,i):
		divs[j]+=1

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

Submission status: Time Limit Exceeded

Solution code:
import math  
  
# method to print the divisors 
def printDivisors(n) : 
    c=0 
    # Note that this loop runs till square root 
    i = 1
    while i <= math.sqrt(n): 
          
        if (n % i == 0) : 
              
            # If divisors are equal, print only one 
            if (n / i == i) : 
                c+=1 
            else : 
                # Otherwise print both 
                c+=2 
        i = i + 1
    return c
  
# Driver method
k=int(input())
res=0
for i in range(1,k+1):
    res+=i*printDivisors(i)
print(res)

Submission status: Time Limit Exceeded

Solution code:

n=int(input())

arr=[0]*(n+1)

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')

#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

ans=0

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]

def make_divisors(n):
    i = 1
    ans = 0
    while i*i <= n:
        if n % i == 0:
            ans += 1
            if i != n // i:
                ans += 1
        i += 1
    return ans

def main():
    N = II()
    ans = 0

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

    print(ans)

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def soinsuu(x):#整数xの素因数分解
    n=x
    bunkai=[]
    for i in range(2,int(n**0.5)+1):
        cnt=0
        while x%i==0:
            x//=i
            cnt+=1
        if cnt==0:
            continue
        bunkai.append([i,cnt])
    if x!=1:
        bunkai.append([n,1])
    ans=1
    for l in bunkai:
        ans*=(l[1]+1)
    return ans

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]

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 = II()
    ans = 0

    for i in range(1,N+1):
        ans += i * len(make_divisors(i))

    print(ans)

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
def func(n):
    div = 0 
    for i in range(1, int(n**0.5)+1):
        if(n%i == 0):
            div += 1
            if(i != n //i):
                div += 1
    return div

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

    ans = 0
    for i in range(1, N+1):
        ans += i*func(i)
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
def func(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)
    return len(divisors)

N = int(input())

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