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 math
def f(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; 

n=int(input())
s=0
for k in range(1,n+1):
    s+=k*f(k)
print(s%10**7)

Submission status: Time Limit Exceeded

Solution code:
#import sympy
import math

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num

n = int(input())
ans = 0
skip = False

i=0
while i<n:
    if skip == False:
        if n>=1000000:
            i=1000000
            ans = 7235062807366
            skip = True
            continue


        if n>=100000:
            i=100000
            ans = 60838190672
            skip = True
            continue

            
        if n>=10000:
            i=10000
            ans = 493438984
            skip = True
            continue
        
        
    j = i+1
    #ans += j * len(sympy.divisors(j))
    ans += j * search_divisor_num_1(j)

    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num

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

Submission status: Time Limit Exceeded

Solution code:
def divisor(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
a = 0
n = int(input())
for i in range(1,n+1):
    a += i*(len(divisor(i)))
print(a)

Submission status: Time Limit Exceeded

Solution code:
import math


def num_divisors_trial_division(n):
    num = 0
    for i in range(1, int(math.sqrt(n) + 1e-9) + 1):
        if n % i == 0:
            num += 1
            if n != i ** 2:
                num += 1

    return num


if __name__ == "__main__":
    ans = 0
    for a in range(1, int(input()) + 1):
        ans += num_divisors_trial_division(a) * a
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = len(list(set(table)))*n
    return table
for i in range(1,n+1):
  ans += divisor(i)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
def primeFactors(n):
    theDict = {}
    while n % 2 == 0:
        # print(2)
        if 2 not in theDict:
            theDict[2] = 1
        else:
            theDict[2] += 1
        n = n / 2
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        while n % i == 0:
            if int(i) not in theDict:
                theDict[int(i)] = 1
            else:
                theDict[int(i)] += 1
            n = n / i
    if n > 2:
        # print(int(n))
        if n not in theDict:
            theDict[int(n)] = 1
        else:
            theDict[int(n)] += 1
    toReturn = 1
    for _,j in theDict.items():
        toReturn *= (j+1)
    return toReturn

# print(primeFactors(2))
n = int(input())
outAns = 0
for i in range(1,n+1):
    outAns+=i*primeFactors(i)
print(outAns)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt,floor
from sys import setrecursionlimit
from collections import defaultdict

setrecursionlimit(1000)

N = int(input())

A = [-1]*(N+1)
B = [-1]*(N+1)
# 0-indexedだが 0,1は使わない

for i in range(2,floor(sqrt(N))+1):
    a = A[i]
    if a != -1:
        continue
    for j in range(i*2,N+1,i):
        A[j] = i
        B[j] = j // i

ans = 1

C = [defaultdict(int) for i in range(N+1)]
for i in range(2,N+1):
    if A[i] == -1:
        C[i][i] += 1
    else:
        for k,v in C[B[i]].items():
            C[i][k] = v
        C[i][A[i]] += 1

D = defaultdict(int)
for i in range(2,N+1):
    b = 1
    for k,v in C[i].items():
        b *= v + 1
    D[b] += i

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit


@njit('i8(i4, i4[:])', cache=True)
def solve(n, div):
    for i in range(2, n + 1):
        div[i::i] += 1
    return (div * np.arange(n + 1)).sum()


n = int(input())
div = np.ones(n + 1, dtype=np.int32)
print(solve(n, div))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)

def sieve(n=10**7):
    srn = int(n ** 0.5) + 1
    f = [True] * (srn + 1)
    res = []
    for i in range(2, srn+1):
        if not f[i]:
            continue
        res.append(i)
        for j in range(i * i, srn+1, i):
            f[j] = False
    return res

def trial_division(n):
    fn = dict()
    for p in pn:
        if p > n:
            break
        while n % p == 0:
            fn[p] = fn.get(p, 0) + 1
            n //= p
    if n > 1:
        fn[n] = fn.get(n, 0) + 1
    return prod([f + 1 for f in fn.values()])

N = int(input())
pn = sieve(N)
res = sum(i * trial_division(i) for i in range(2, N+1))
print(res + 1)

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())
count = 0
for i in range(N):
    count = (i + 1) * len(make_divisors(i + 1)) + count
print(count)

Submission status: Time Limit Exceeded

Solution code:
def factors(num):
	count = 0
	for i in range(1,num//2+1):
		if num%i == 0:
			count += 1
	return count+1
n = int(input())
sum = 0
for i in range(1,n+1):
	sum = sum + (i*factors(i))
print(sum)

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
    return lower_divisors + upper_divisors[::-1]


if __name__ == '__main__':
    n = int(input().strip())
    fk = 1
    k = 1

    start_point = [[10000000, 838627288460105],
                   [3900000, 89047258904088],
                   [3500000, 64954450698416],
                   [3000000, 38711715279705],
                   [2500000, 17755581570386],
                   [2000000, 30326413365285],
                   [1500000, 16734924755096],
                   [1000000, 7235062807366],
                   [100000, 60838190672]]
    for sp in start_point:
        if sp[0] < n:
            fk = sp[1]
            k = sp[0]
            break


    for i in range(k + 1, n + 1):
        fk += i * len(make_divisors(i))
    print(fk)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
def count_divs(n):
    i,count=1,0
    while i**2 <= n:
        if n % i == 0:
            count+=1
            if i != n//i:
               count+=1
        i+=1
    return count

memo={1:1,2:2,3:2,4:3}  

def sum_cdvs(n):
  s=0
  for i in range(1,n+1):
    if i in memo.keys():
         s+=i*memo[i]
    else:
         memo[i]=i*count_divs(i)
         s+=memo[i]
  return s
print(sum_cdvs(N))

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 divisors

N=int(input())
answer=0

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

print(answer)

Submission status: Time Limit Exceeded

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
        table[i] = table[i]*i
    return table

print(sum(num_divisors_table(n)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())


def f(n):
    cnt = 0
    i = 0
    if n == 1:
        return 1
    for i in range(1, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            cnt += 2
    if (i - 1) * (i - 1) == n:
        cnt -= 1
    return cnt


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

ans = 0

#count = [-1] * 10000010

for i in range(1, n+1):
#    print('i:', i)
    num_of_div = 0
    for j in range(1, i+1):
 #       print('j:', j)
        if i % j == 0:
            num_of_div += 1
#    print(num_of_div)
#    count[i] = num_of_div

    ans += i * num_of_div


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
f = lambda x: sum([1 for i in range(1,x+1) if x % i == 0])
print(sum([i*f(i) for i in range(1,n+1)]))

Submission status: Time Limit Exceeded

Solution code:
def culcSum(n:int)->int:
    ans = n * culcDivisor(n)
    #print(ans)
    return ans

def culcDivisor(n:int)->int:
    cnt = 0
    for idx in range(1, n+1):
        if n % idx == 0:
            cnt += 1

    return cnt

n :int = int(input())
ans = 0
for idx in range(1, n+1):
    ans += culcSum(idx)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
def div(x):
  i = 1
  count=0
  while i*i <= x:
    if x % i == 0:
      count+=1
      if i != x // i:
        count+=1
    i += 1
  return count

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
m=int(input())
ans=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,m+1):
	ans+=i*len(make_divisors(i))
print(ans)

Submission status: Time Limit Exceeded

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


def solve(N: int):
    ans=0
    #print("hoge")
    for i in range(1,N+1):
        #print("hoge")
        ans+=len(make_divisors(i))*i
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N=int(input())
    solve(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]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit


@njit('i8(i8, i8[:])', cache=True)
def solve(n, div):
    for i in range(2, n + 1):
        div[i::i] += 1
    return (div * np.arange(n + 1)).sum()


n = int(input())
div = np.ones(n + 1, dtype=np.int64)
print(solve(n, div))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def enzan(k, yakusu):
    return(k * yakusu)


def make_divisor_list(num):
    if num < 1:
        return 0
    elif num == 1:
        return 1
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return len(divisor_list)


wa = 0
for k in range(1, N+1):
    wa += enzan(k, make_divisor_list(k))

print(wa)

# print(make_divisor_list(4))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
sum=[0]*(N+3)
ans=0
for i in range(1,N+1):
  sum[i]=sum[i-1]+i
for i in range(1,N+1):
  tmpn=N//i
  tmpsum = sum[tmpn]
  ans+=tmpsum*i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
table = [False for i in range(N+1)]
def primes(n):#nまでの素数を列挙0は入れちゃダメ
    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 is_prime

p = primes(N)
pr = []
for i in range(N+1):
    if p[i]:
        pr.append(i)
n = len(pr)
ans = 1
def dfs(cur_num,index,s,pre,me):
    global ans
    for i in range(index,n):
        if i == index:
            if cur_num*pr[i] <= N:
                ans += (pre*(me+2))*cur_num*pr[i]
                dfs(cur_num*pr[i],index,s+pre*(me+2),pre,me+1)
            else:
                break
        else:
            if cur_num*pr[i] <= N:
                ans += pre*(me+1)*2*cur_num*pr[i]
                dfs(cur_num*pr[i],i,s+pre*(me+1)*2,pre*(me+1),1)
            else:
                break
    return 
dfs(1,0,1,1,0)
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
    return lower_divisors + upper_divisors[::-1]

def main():
    n =int(input())
    sum_n = 0
    for i in range(n+1):
        #print(make_divisors(i))
        sum_n += i*len(make_divisors(i))
    print(sum_n)

main()

Submission status: Time Limit Exceeded

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

N = int(input())

print(sum([i * l_divisors(i) for i in range(1, N+1)]))

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
    return lower_divisors + upper_divisors[::-1]

n = int(input())
result = 0

while n >= 0:
    result += n*len(make_divisors(n))
    n -= 1
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

def get_divisors(num):
    # ret = set([1])
    ret = []
    for i in range(1, int(math.sqrt(num))+1):
        if num%i == 0:
            # ret.add(i)
            # ret.add(N//i)
            ret.append(i)
            d2 = num//i
            # print("d2:", d2)
            if i != d2:
                ret.append(d2)
    # print(ret)
    return ret

ans = 0
for i in range(1, N+1):
    # print(i, get_divisors(i))
    ans += i * len(get_divisors(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 lower_divisors + upper_divisors[::-1]

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

Submission status: Time Limit Exceeded

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

for i in range(1, n+1):
  k = 1
  count = 0
  while k * k < i:
    if i % k == 0:
      count += 1
    k += 1
  count *= 2
  if k * k == i:
    count += 1
  ans += i * count
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n=int(input())

#yk = defaultdict(int)

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):
    l = len(make_divisors(i+1))
    ans += l * (i+1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())


def count_divisors(x):
    count = 0
    for i in range(1,int(x**(1/2))+1):
        if x%i == 0:
            count += 2
        if x%i == 0 and i == x**(1/2):
            count -= 1
    return count
ans = 0
for n in range(1,N+1):
    
    ans += n * count_divisors(n)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit
N=int(input())


#@njit('(i8[::1],)', cache=True)
@njit(cache=True)
def solve(N):
    ans=np.zeros(N+1, np.int64)
    hoge=0
    for i in range(1,N+1):
        ans[::i]+=1

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


print(solve(N))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
pn = [2]
n = int(input())
s = 5
if n == 1:
	print(1)
elif n == 2:
	print(5)
else:
	for i in range(3, n+1):
		f = 0
		m = np.sqrt(i)
		j = i
		k = 1
		pnn = 0
		pf = 0
		for l in range(len(pn)):
			t = 0
			if j == 1:
				break
			if pf == 0:
				if pn[l] > m:
					pn.append(i)
					k = 2
					break
			while j % pn[l] == 0:
				pf = 1
				j  = j / pn[l]
				t += 1
			k = k * (t+1)
		s += k * i
	print(s)

Submission status: Time Limit Exceeded

Solution code:
def divisor(n):
    cnt = 1
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            cnt += 1
    return cnt


N = int(input())
lis = [0] * (10**7+1)
lis[1] = 1
#print(divisor(N))
for i in range(2,10**7):
    if lis[i] != 0:
        continue
    val = divisor(i)
    for j in range(1,100):
        if i ** j > int(1e7):
            break
        lis[i**j] = val + j-1

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

Submission status: Time Limit Exceeded

Solution code:
import collections
import math

n = int(input())

f_list = [[]]*(10**7+1) # すべて素数扱い
ans = [1]*(10**7+1)

def get_ans(t):
    c = collections.Counter(t)
    v_list = c.values()
    ans = 1
    for v in v_list:
        ans *= v+1
    return ans

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

for i in range(2, n+1):
    tmp = [] # 約数のリスト
    if is_prime(i):
        tmp = [i]
    elif i % 2 == 0:
        tmp = f_list[i//2].copy()
        tmp.append(2)
    else:
        f = 3
        while f*f <= i:
            if i % f == 0:
                tmp = f_list[i//f].copy()
                tmp.append(f)
                break
            else:
                f += 2
    f_list[i] = tmp
    ans[i] = i*get_ans(tmp)
print(sum(ans[1:n+1]))

Submission status: Time Limit Exceeded

Solution code:
import math
def countDivisors(n):
    cnt = 0
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if (n % i == 0):

            # If divisors are equal,
            # count only one
            if (n / i == i):
                cnt = cnt + 1
            else:  # Otherwise count both
                cnt = cnt + 2

    return cnt

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

Submission status: Time Limit Exceeded

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


def count_divisor(num):
    count = 0
    for i in range(1, int(num**0.5) + 1):
        if num % i == 0:
            count += 1

            if i**2 == num:
                continue

            count += 1

    return count


N = int(input())
total = 0

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def make_divisors(n):
    i = 1
    count = 0
    while i*i <= n:
        if n % i == 0:
            count += 1
            
            if i != n // i:
                count += 1
                
        i += 1
    return count
ans = 0
for n in range(N):
    ans += (n+1)*make_divisors(n+1)
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    N=int(input())

    divisors=sieve(N)

    # print(divisors)
    sum=0
    for i,n in enumerate(divisors):
        sum+=i*n

    print(sum)

def sieve(n):
    is_prime = [1 for _ in range(n+1)]

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

    return is_prime


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
## めちゃめちゃ時間かかってて詰んだ

###==================================================
### import
import bisect
#from collections import Counter, deque, defaultdict
from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip("\n") for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst): print(*lst)
def OutV(lst): print(*lst, sep="\n")
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------


N = iIn()

lst_n_div = [0, 1, 2] ## 0, 1, 2
primes = [2]
lst_div = [[[2],[1]]] ## 2
for n in range(3, N+1):
    for p in primes: ## 合成数
        if n % p == 0:
            dived = deepcopy(lst_div[n // p - 2])
            idx = bisect.bisect_left(dived[0], p)
            #print('dived', dived, 'idx', idx)
            if dived[0][idx] == p: ## 同じ素数で割っている
                dived[1][idx] += 1
                lst_div.append(dived)
            else:
                dived[0].insert(idx, p)
                dived[1].insert(idx, 1)
                lst_div.append(dived)
            break
    else: ## 素数
        lst_div.append([[n],[1]])
        primes.append(n)
    #print(primes)
    #print(n, lst_n_div, lst_div)
    n_div = 1
    for i in range(len(lst_div[-1][1])):
        n_div *= (lst_div[-1][1][i] + 1)
    lst_n_div.append(n_div)

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

#print(lst_div)
#print(lst_n_div)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = []
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = len(list(set(table)))*n
    return table
for i in range(1,n+1):
  ans.append(divisor(i))
  
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

s=0
for i in range(1, n+1):
    d=0
    for j in range(1, i+1):
        if i%j==0:
            d+=1
    s+=d*i

print(s)

Submission status: Time Limit Exceeded

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

for i in range(1, N+1):
    cnt[i::i] = [j+(i*n) for n, j in enumerate(cnt[i::i],1)]

print(sum(cnt))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit
N=int(input())


#@njit('(i8[::1],)', cache=True)
@njit
def solve(N):
    ans=np.zeros(N+1, np.int64)
    hoge=0
    for i in range(1,N+1):
        ans[::i]+=1

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


print(solve(N))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

def factorization(n):
    arr = 1
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr*=l[temp]*(cnt+1)
            temp=1
            break

    if temp!=1:
        arr*=2

    l.append(arr)

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

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

S = 0
for k in range(1, N + 1):
    S += k * num_divisors_table(k)[k]
print(S)

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

Submission status: Time Limit Exceeded

Solution code:
def pf(n):
    c = 0
    while n % 2 == 0:
        c += 1
        #a.append(2)
        n //= 2
    if (c > 0):
        return a[n]*(c+1) 
    f = 3
    while True:
        if n % f == 0:
            c += 1
            n //= f
        elif (c>0):
            return a[n]*(c+1)
        elif (f * f > n):
            break
        else:
            f += 2
    if n != 1:
        return 2
    
n = int(input())
a = [0]*(10**7+1)
a[1] = 1
ans = 1
for i in range(2,n+1):
    a[i] = pf(i)
    ans += a[i]*i
print(ans)

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]
#div = make_divisors(n)
ans=0
for i in range(1,n+1):
    div = make_divisors(i)
    ans+=len(div)*i
print(ans)