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:
from math import floor
n = int(input())

res = 0
for i in range(1, n+1):
    if i != 1:
        factors = 0
        for j in range(1, floor(i**0.5) + 1):
            if i % j == 0:
                factors += 1
        
        if floor(i ** 0.5) ** 2 == i:
            res += i * (factors*2-1)
        else: res += i * (factors*2)
    else: res += 1
print(res)

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())
prime_number = []


def f_func(X):
    x = X
    ans = [0] * (x - 1)

    pn = 0
    n = 1
    while n <= x:
        if pn < len(prime_number):
            n = prime_number[pn]
        else:
            n += 1

        j = 1
        while True:
            mod = x % n
            if mod != 0:
                break
            x = x // n
            j += 1
        ans[n - 2] = j - 1
        pn += 1


    result = 1
    for i in ans:
        result = result * (i + 1)
    if sum(ans) == 1:
        prime_number.append(X)
    return result

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())


def f_func(X):
    ans = [0] * (X - 1)
    n = 2
    for _ in range(X - 1):
        j = 1
        while True:
            mod = X % n
            if mod != 0:
                break
            ans[n-2] = j
            X = X // n
            j += 1
        n += 1
    result = 1
    for i in ans:
        result = result * (i + 1)
    return result

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

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import Counter
from functools import lru_cache


@lru_cache(maxsize=10 ** 6)
def get_prime_factors(n):
    limit = int(math.sqrt(n))
    for i in range(2, limit + 1):
        if n % i == 0:
            return [i] + get_prime_factors(n // i)
    return [n]

def count_factors(n):
    if n == 1:
        return 1
    else:
        prime_factors = get_prime_factors(n)
        counter = Counter(prime_factors)
        return math.prod([count + 1 for count in counter.values()])

N = int(input())

print(sum([count_factors(n) * n for n in range(1, N + 1)]))

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def divisor(x):
  i = 1
  div = []
  while i * i <= x:
    if x % i == 0:
      div.append(i)
      div.append(x // i)
    i += 1
  div = list(set(div))
  return len(div)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Sum of Divisors
N = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
def calc(sykou,makkou,kousuu):
    return int((sykou+makkou)/2*kousuu)

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

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
sum = 0
for i in range(N):
  sum += (i+1)*divitorCount(i+1)

print(sum)

Submission status: Time Limit Exceeded

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

List = [0 for i in range(n+1)]
for i in range(1,n+1):
    for k in range(0,n+1,i):
        if k == 0:
            continue
        List[k] += 1

for x in range(len(List)):
    answer += x*List[x]

print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
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 ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def factorize(N):
    def gcd(a, b):
        while b: a, b = b, a % b
        return a
    def isPrimeMR(n):
        d = n - 1
        d = d // (d & -d)
        L = [2]
        for a in L:
            t = d
            y = pow(a, t, n)
            if y == 1: continue
            while y != n - 1:
                y = (y * y) % n
                if y == 1 or t == n - 1: return 0
                t <<= 1
        return 1
    def findFactorRho(n):
        m = 1 << n.bit_length() // 8
        for c in range(1, 99):
            f = lambda x: (x * x + c) % n
            y, r, q, g = 2, 1, 1, 1
            while g == 1:
                x = y
                for i in range(r):
                    y = f(y)
                k = 0
                while k < r and g == 1:
                    ys = y
                    for i in range(min(m, r - k)):
                        y = f(y)
                        q = q * abs(x - y) % n
                    g = gcd(q, n)
                    k += m
                r <<= 1
            if g == n:
                g = 1
                while g == 1:
                    ys = f(ys)
                    g = gcd(abs(x - ys), n)
            if g < n:
                if isPrimeMR(g): return g
                elif isPrimeMR(n // g): return n // g
                return findFactorRho(g)
    def primeFactor(n):
        i = 2
        ret = {}
        rhoFlg = 0
        while i*i <= n:
            k = 0
            while n % i == 0:
                n //= i
                k += 1
            if k: ret[i] = k
            i += 1 + i % 2
            if i == 101 and n >= 2 ** 20:
                while n > 1:
                    if isPrimeMR(n):
                        ret[n], n = 1, 1
                    else:
                        rhoFlg = 1
                        j = findFactorRho(n)
                        k = 0
                        while n % j == 0:
                            n //= j
                            k += 1
                        ret[j] = k
        if n > 1: ret[n] = 1
        if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
        return ret
    return primeFactor(N)

N = INT()

ans = 0
for i in range(1, N+1):
    res = factorize(i)
    cnt = 1
    for v in res.values():
        cnt *= v + 1
    ans += cnt * i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

ans=0

for k in range(1,n+1):
  cnt=0
  for i in range(1,k+1):
    if k%i==0:
      cnt+=1
  ans+=k*cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

yakusus = {}
result = 0

for nn in range(1,n+1):
	counter = 0
	for nnn in range(nn,0,-1):
		if nn % nnn == 0:
			got = yakusus.get(nn)
			if got is not None:
				counter += got
				break
			else:
				counter += 1
	yakusus[nn] = counter
	result += nn * counter

print(result)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N=input()
L=defaultdict(lambda: 1)
L[1]=1
for skip in range(2,N+1):
    for i in range(skip,N+1,skip):
        L[i]+=1
ans=0
for k in range(1,N+1):
    ans+=k*L[k]

print ans

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [0]*(n+1)
asum = 1

for i in range(2,n+1):
    a[i] += 1
    for k in range(i,n+1,i):
        a[k] += 1
    asum += i*a[i]
print(asum)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

print(num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

num = 0
for i in range(1,N+1):
    num += sum(range(i,N+1,i))

print(num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def num_of_divisor(K):
    num = 0
    for i in range(1,int(K**0.5)+1):
        if K%i == 0:
            num += 2
    if K**0.5 == int(K**0.5):
        num -= 1
    return num

ans = 0
for K in range(1,N+1):
    ans += K*num_of_divisor(K)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def mdiv(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=chk=0
for i in range(1,n+1):
    ans+=i*len(mdiv(i))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def div_count(N):
    divs = 0
    for i in range(1, int(N**0.5) + 1):
        if not N % i:
            divs += 1
            if i != N // i:
                divs += 1
    return divs

def solve():
    ret = 0
    for k in range(1, N + 1):
        ret += k * div_count(k)
    print(ret)

if __name__ == "__main__":
    N = int(input())
    solve()

Submission status: Time Limit Exceeded

Solution code:
from math import *
from collections import defaultdict
GLOBAL = {}
def roots(n):
	res = set()
	for i in range(1,int(sqrt(n))+1):
		if n%i == 0:
			res.add(i)
			res.add(n//i)
	return len(res)

n = int(input())
cnt = 0
for i in range(1,n+1):
	try:
		cnt+=i*GLOBAL[i]
	except:
		GLOBAL[i]=roots(i)
		cnt+=i*GLOBAL[i]
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for j in range(1, n+1):
    if j == 1:
        ans += 1
    else:
        dnum = 2
        s = int(j ** 0.5)
        for i in range(2, s+1):
            if j % i == 0:
                if i == j // i:
                    dnum += 1
                else:
                    dnum += 2
        ans += j * dnum
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N=int(input())
ans=0
for k in range(1,N+1):
    c = collections.Counter(prime_factorize(k))
    pow=list(c.values())
    buf=1
    for p in pow:
        buf*=p+1
    ans+=k*buf
print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()  
    
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]
ans=0

for i in range(n): 
    ans+=(i+1)*len(make_divisors(i+1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def calc():
 n=int(input())
 table=[0]*(n+1)
 for i in range(1,n+1): #各iについて、iの倍数の約数の個数table[i*j]を1増やす
   for j in range(i,n+1,i):
     table[j]+=1
 ans=0
 for i in range(1,n+1):
   ans+=i*table[i] #すべてのKについてf(K)を求められたので答えを計算する
 print(ans)
calc()

Submission status: Time Limit Exceeded

Solution code:
# D - Sum of Divisors
N = int(input())
ans = (1 + N) * N

for i in range(2, N//2 + 1):
	j = 2
	
	while True:
		if i * j <= N:
			
			ans += i * j
			j += 1
		else:
			break

print(ans - 1)

Submission status: Time Limit Exceeded

Solution code:
# D - Sum of Divisors
N = int(input())
ans = (1 + N) * N // 2

for i in range(2, N + 1):
	j = 1
	
	while True:
		if i * j <= N:
			#print(i * j)
			
			ans += i * j
			j += 1
		else:
			break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Sum of Divisors
N = int(input())
ans = 0

for i in range(1, N + 1):
	j = 1
	
	while True:
		if i * j <= N:
			#print(i * j)
			
			ans += i * j
			j += 1
		else:
			break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Sum of Divisors
N = int(input())

# 1と自分自身はかならず約数になるので、計算から除外
f = [2] * (N + 1)

for i in range(2, N//2 + 1):
	j = 2
	
	while True:
		if i * j <= N:
			f[i*j] += 1
			j += 1
		else:
			break

ans = 1

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math


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

    def count_yakusu(num):
        count = 0
        range1 = math.floor(math.sqrt(num))
        for i in range(1, range1+1):
            if num % i == 0:
                if num / i == i:
                    count += 1
                else:
                    count += 2
        return count

    amount = 0
    for i in range(1, n+1):
        amount += i * count_yakusu(i)

    print(amount)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# D - Sum of Divisors
N = int(input())
count = [1] * (N + 1)

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    n_ = int(n**0.5)
    ans = [2 for i in range(n)]
    ans[0] = 1
    for i in range(2,n_+1):
        for j in range(i+1,n+1):
            if j%i==0:
                if j==i*i:
                    ans[j-1]+=1
                elif j> i*i:
                    ans[j-1]+=2
    s=0
    for i in range(n):
        s += (i+1)*ans[i]
    print(s)


if __name__ == "__main__":
    main()

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	__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()
dic = dict()

for i in range(N, 1, -1):
	if not i in dic.keys():
		factors = lib.get_factors(i)
		divisors = dict()
		divisors[1] = 1
		
		for k, v in factors.items():
			import copy
			copied = copy.deepcopy(divisors)

			for j in range(1, v + 1):
				for c_k, c_v in copied.items():
					d = c_k * (k ** j)			
					count = c_v * (j + 1)
					divisors.setdefault(d, count)

					dic.setdefault(d, 0)
					dic[d] = count

ans = 1

for k, v in dic.items():
	ans += k * v

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
 
sum1 = 0
for m in range(1, N + 1):
  sum2 = 0
  for i in range(1, m + 1):
    if m % i == 0:
      sum2 += 1
  sum1 += m * sum2
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sum1 = 0
for m in range(1, N + 1):
  sum2 = 0
  for i in range(1, m + 1):
    if m % i == 0:
      sum2 += 1
  sum1 += m * sum2
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
data = [0] * (n + 1)
for i in range(1,n + 1):
  for d in range(1,n + 1):
    if d % i == 0:
      data[d] += 1
      #print("d = " + str(d)  + "i = " + str(i))
      #print(data)

data.pop(0)
ans = 0

x = 1
for i in data:
  #print("x = " + str(x) + " i = " + str(i))
  ans = ans + (x * i)
  x += 1

print(ans)

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:
import math
n = int(input())

ans = 0

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

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
out=0
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]
for i in range(1,N+1):
    out+=len(make_divisors(i))*i
print(out)

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
def func(i):
  return len([1 for n in range(i) if i%(n+1) == 0])
sums = 0
for i in range(N):
  sums += (i+1)*func(i+1)
print(sums)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

#約数の個数を求める関数
def yakusu_count(n):
    count = 1
    if n == 1:
        pass
    elif n == 3:
        count =2

    elif n % 2 == 0:
        for i in range(1,n//2 + 1):
            if n % i == 0:
                count += 1

    elif n % 2 == 1:
        for i in range(1, n//2):
            if n % i == 0:
                count += 1
    
    return count

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

Submission status: Time Limit Exceeded

Solution code:
"https://codeforces.com/contest/1328/problem/A"
import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs  = lambda: input()
ri  = lambda: int(input())
rm  = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]

from functools import reduce

def solve():
    N = ri()
    ans = 0
    for i in range(1, N+1):
        for j in range(1, N+1):
            if i%j == 0:
                ans += i
    return ans
print(solve())

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
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 lower_divisors + upper_divisors[::-1]

num_yaku = len(make_divisors(N))

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

print(sum_num)

Submission status: Time Limit Exceeded

Solution code:
import math

n=int(input())

def kf(n):
  ans=0
  yaku=1
  for k in range(1, n+1):
    x=k
    f=1
    for j in range(2, round(math.sqrt(x))+2):
      tmp=1
      if x < 2:
        break
      while x % j == 0:
        x=x//j
        tmp+=1
      f*=tmp
    if x > 1:
      f*=2
    ans+=k*f
  return ans

print(kf(n))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

def kf(n):
  ans=0
  for k in range(1, n+1):
    for j in range(1, k+1):
      if k % j == 0:
        ans+=k
  return ans

print(kf(n))

Submission status: Time Limit Exceeded

Solution code:
import math

n=int(input())

def yaku2(u, n):
  ans=0
  for v in range(1, u+1):
    ans+=math.cos(2*math.pi*v*n/u)
  return ans

def yaku(n):
  ans=0
  for i in range(1, n+1):
    ans+=yaku2(i, n)/i
  return round(ans)

def func(n):
  ans=0
  for i in range(1, n+1):
    ans+=i*yaku(i)
  return ans

print(func(n))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

answer = [None for i in range(0, n+1)]
answer[1] = 1

small_factors = [1]
p = 1
while (p < n):
    p = p + 1
    if answer[p] is None:
        #print("\n\nPrime: " + str(p))
        limit = n / p
        new_small_factors = []
        for i in small_factors:
            j = i
            while j <= limit:
                new_small_factors.append(j)
                answer[j * p] = answer[j] + answer[i]
                j = j * p
        small_factors = new_small_factors
answer.pop(0)
s=0
for  i in range(n):
    s=s+(i+1)*(answer[i])
print(s)

Submission status: Time Limit Exceeded

Solution code:
# エラトステネスの篩
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(n ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        c = 0
        while n % p == 0:
            n //= p
            c += 1
        result.append(c)
    return result


def f(X):
    result = 1
    for c in prime_factorize(X):
        result *= c + 1
    return result


N = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
# エラトステネスの篩
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(n ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        c = 0
        while n % p == 0:
            n //= p
            c += 1
        result.append((p, c))
    return result


def f(X):
    result = 1
    for _, c in prime_factorize(X):
        result *= c + 1
    return result


N = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
# エラトステネスの篩
N = int(input())


def make_prime_table(N):
    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
    return sieve


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


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

Submission status: Time Limit Exceeded

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

def g(x):
    y = int(N/x)
    return y*(y+1)*x/2

for i in range(1,N+1):
    ans.append(g(i))

#print(ans)
print(int(sum(ans)))

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

def count_divisor(n):

    ans = 0
    
    i=1
    while i*i <= n:
        syou, amari = divmod(n,i)
        #print(syou, amari)
        if(amari == 0):
            ans += 1
            if( syou != i):
                ans += 1
        i+=1
    return ans

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

print(ans)

Submission status: Time Limit Exceeded

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

    ans += (l[i]*i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
Arr = []
N = int(input())
for i in range(N+1):
    Arr.append(0)
for i in range(1, N+1):
    for j in range(i,N+1,i):
        Arr[j] += 1
for i in range(1, N+1):
    Arr[i] = i*Arr[i]

print(sum(Arr))

Submission status: Time Limit Exceeded

Solution code:
import math


def numOfDivisors(x):
    res = 0
    k = int(math.sqrt(x))
    for i in range(1, k+1):
        if x%i ==0: res+=2
    if k*k==x: res-=1
    return res

N = int(input())
res = 0
for i in range(1, N+1):
    res += i*numOfDivisors(i)
print(res)

Submission status: Time Limit Exceeded

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

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

    l[i] = l[i]*i

print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

print(int(sum_))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

def smallestPrimeFactor(mxn): 
    spf = [i for i in range(1+mxn)]

    for i in range(4, 1+mxn, 2):
        spf[i] = 2

    for i in range(3, int(mxn**0.5)+1):
        if spf[i] == i:
            for j in range(i*i, mxn, i):
                if spf[j] == j:
                    spf[j] = i
                    
    return spf

n = int(input())
spf = smallestPrimeFactor(1+n)
ans = 0

for i in range(1, n+1):
    num = i
    d = defaultdict(int)
    d[1] = 0
    
    while i != 1:
        d[spf[i]] += 1
        i //= spf[i]
        
    prod = 1
    for k,v in d.items():
        prod *= (v+1)
    ans += prod*num
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# usage: ./yakusuu.py 30

number = int(input())


answer=0
for K in range(1,number+1):
    f=0
    yakusuu_array = []
    
    for i in range(1,K+1):

        if K % i == 0 :
            f+=1
            
            yakusuu_array.append(i)

    #print(K)
    #print(yakusuu_array)
    answer+=(f*K)

print(answer)

Submission status: Time Limit Exceeded

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