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:
N = int(input())
K = list()
ans = 0

for i in range(1, N+1):
    num = 0
    for j in range(1, i+ 1):
        if(i % j == 0):
            num += 1
        else:
            pass
    ans += i * num
    
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]

N = int(input())
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())
count1=[c for c in range(N+1)]
count2=[2*c for c in range(N+1)]
count2[1]=1

i=2
while i<=N//2+1:
    j=2
    while i*j<=N:
        count2[i*j]+=count1[i*j]
        j+=1
    i+=1

print(sum(count2))

Submission status: Time Limit Exceeded

Solution code:
"""
~~ Author : Bhaskar
~~ Dated : 10~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
input = lambda : sys.stdin.readline()

def seive(n):
    prime = [0 for i in range(n + 1)]
    p = 2
    for i in range(1, n+1):
        for j in range(i, n+1, i):
            prime[j] += 1
        p += 1
    cnt = 0
    for i in range(1, n + 1):
        cnt += i * prime[i]
    return cnt

def solve():
    n = int(sys.stdin.readline())
    print(seive(n))


if __name__ == "__main__":
    try:
        sys.stdin = open('input.txt','r')
        sys.stdout = open('output.txt','w')
    except:
       pass
    solve()

Submission status: Time Limit Exceeded

Solution code:
import math as mt 
import collections
N = int(raw_input())
MAXN = N+1
  
# stores smallest prime factor for 
# every number 
spf = [0 for i in range(MAXN)] 
  
# Calculating SPF (Smallest Prime Factor)  
# for every number till MAXN. 
# Time Complexity : O(nloglogn) 
def sieve(): 
    spf[1] = 1
    for i in range(2, MAXN): 
          
        # marking smallest prime factor  
        # for every number to be itself. 
        spf[i] = i 
  
    # separately marking spf for  
    # every even number as 2 
    for i in range(4, MAXN, 2): 
        spf[i] = 2
  
    for i in range(3, int(mt.ceil(mt.sqrt(MAXN)))): 
          
        # checking if i is prime 
        if (spf[i] == i): 
              
            # marking SPF for all numbers 
            # divisible by i 
            for j in range(i * i, MAXN, i):  
                  
                # marking spf[j] if it is  
                # not previously marked 
                if (spf[j] == j): 
                    spf[j] = i 
# A O(log n) function returning prime  
# factorization by dividing by smallest  
# prime factor at every step 
def getFac(x): 
    ret = list() 
    while (x != 1): 
        ret.append(spf[x]) 
        x = x // spf[x] 
  
    return ret 


sieve() 
ans = 0
for i in range(1,N+1):
    fac = getFac(i)
    if len(fac) == 1:
        ans += i*2
    else:
        res = 1
        dic = collections.Counter(fac)
        for v in dic.values():
            res*=(v+1)
        ans+= res*i
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:
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())
cnt=0
for i in range(1,n+1):
    cnt+=i*len(make_divisors(i))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

def countDiv(n):
  ans = 0
  for i in range(1, (int)(math.sqrt(n))+1):
    if n%i == 0:
      if n/i == i:
        ans += 1
      else:
        ans += 2
  return ans

n = int(input())

divisors = []

div = [0 for i in range(n+1)]
for i in range(1, n+1):
  j = i
  while j<=n:
    div[j] += 1
    j += i

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

Submission status: Time Limit Exceeded

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

def num_d(x):
  return sum(x for i in range(1,x+1) if x%i==0)

N=int(input().rstrip('\n'))
res = 0
time = N // 10
last = N % 10
if time>=1:
  for i in range(time):
    res += num_d(i*10+1)
    res += num_d(i*10+2)
    res += num_d(i*10+3)
    res += num_d(i*10+4)
    res += num_d(i*10+5)
    res += num_d(i*10+6)
    res += num_d(i*10+7)
    res += num_d(i*10+8)
    res += num_d(i*10+9)
    res += num_d(i*10+10)
  if last >= 1:
    for i in range(1,last+1):
      res += num_d(10*time+i)
else:
  for i in range(1,last+1):
    res += num_d(i)
print(res)

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

for i in range(1, n + 1):
  if n != sum:
    sum += i * len(make_divisors(i))
  else:
    break

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]


n = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
def make_divisor_list(num):
    if num < 1:
        return []
    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 divisor_list

print(sum(i*len(make_divisor_list(i)) for i in range(1,N+1)))

Submission status: Time Limit Exceeded

Solution code:
import sys

inputNum = int(input())
count = 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, inputNum + 1):
    count += i * len(make_divisors(i))

print(count)

Submission status: Time Limit Exceeded

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

N = int(input())
ans = 0
for i in range(1, N+1):
    divsum = sum(range(1, N//i + 1))
    ans += divsum*i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def div(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
  
n = int(input())
#print(len(div(n)))

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

Submission status: Time Limit Exceeded

Solution code:
def 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())

total = 0
for i in range(1,n+1):
    div = divisors(i)
    total += i * len(div)
print(total)

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())


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


k = 1
R = 0

while k <= N:
    R += k * make_divisors(k)
    k += 1

print(R)

Submission status: Time Limit Exceeded

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

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

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)

# テスト
N = int(input())
#print("約数 =", divisors(N))
#print("素因数分解 = ", primeFactor(N)) 

ans = 0
for i in range(1,N+1):
    A = primeFactor(i).values()
    chk = 1
    for a in A:
        chk *= (a+1)
    ans += chk*i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    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)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
def factorization(n):
    res = 1
    tmp = n
    for i in range(2, int(n**0.5)+1):
        if tmp % i == 0:
            cnt = 1
            while tmp % i == 0:
                cnt += 1
                tmp //= i

            res *= cnt

        if tmp == 1:
            break
    if tmp != 1:
        res *= 2

    return res

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def factorization(n):
    arr = []
    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.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())

s = 0

for k in range(n):
  p = k+1
  for l in range(len(factorization(k+1))):
    p *= (factorization(k+1)[l][1]+1)
  s += p
  
print(s-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import numpy as np
import functools
import operator
import collections
import itertools
#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())
ans=0
for i in range(1,N+1):
    ans+=i*len(make_divisors(i))
print(ans)

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
N=int(input())
ans=[]
li=[i for i in range(1,N+1)]
for i in range(1,N+1):
  ans.append(num_divisors_trial_division(i))
print(sum([a*b for a,b in zip(ans,li)]))

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())
ans = 0
for x in range(1,n+1):
    #print(x,len(sympy.divisors(x)))
    ans += x * (len(make_divisors(x)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# d

n = int(input())
d = []

for j in range(1, n+1):
    div = 0
    for i in range(1, j+1):
        if j % i == 0:
            div += 1
    d.append(div)

sum = 0        
for k in range(1, n+1):
    sum += (d[k-1] * k) 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
def divisor_num(n):
    a = 1
    for _, x in factorization(n):
        a *= x + 1
    return a

print(sum(i*divisor_num(i) for i in range(1,N+1)))

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)

	return divisors

N=int(input())

res=0
for k in range(1,N+1):
	res+=k*len(make_divisors(k))
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
conv = [0]*(N+1)
for i in range(1,N+1):
    for j in range(1,N//i+1):##その数の倍数をメモ
        conv[i*j-1] += 1
   
##print(conv)
print(sum([(i+1)*conv[i] for i in range(N)]))

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
a = [0]*10**7
x = math.sqrt(10)
b = math.floor(x)
l = 0
for i in range(1,n+1):
  x = math.sqrt(i)
  b = math.floor(x)
  for j in range(1,b+1):
    if(i%j==0 and i//j == j):
      a[i-1] +=1
    elif(i%j==0):
      a[i-1] +=2
for k in range(n):
  l = l + a[k]*(k+1)
print(l)

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


c = 0
for k in range(1, n + 1):
    c += k * make_divisors(k)
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(20000000)

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
def factrize(x):
    f = {}
    if x == 1:
        return f
    tmp = x
    i = 2
    while i**2 <= tmp:
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp = tmp//i
        if cnt > 0:
            f[i] = cnt
        i += 1
    if tmp != 1 or f == {}:
        f[tmp] = 1
    return f
n = int(input())
b = []
for i in range(1, n+1):
  a = factrize(i)
  A = list(a.values())
  ans = 1
  for j in A:
    ans *= j+1
  b.append(ans)
ansans= 0
for i, j in enumerate(b):
  ansans += (i+1)*j
print(ansans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

###素因数分解高速###
NN = 10 ** 7 + 10
primes = []
isprime = [True for _ in range(NN + 1)]
min_factor = [-1 for _ in range(NN + 1)]
#エラトステネスの篩
for i in range(2, NN + 1):
    if not isprime[i]:
        continue
    primes.append(i)
    min_factor[i] = i
    for j in range(i * 2, NN + 1, i):
        isprime[j] = False
        if min_factor[j] == -1:
            min_factor[j] = i
def prime_factorize(n):
    res = []
    while n != 1:
        prime = min_factor[n]
        exp = 0
        while min_factor[n] == prime:
            exp += 1
            n //= prime
        res.append(exp)
    return res
##/素因数分解高速/##

n = INT()
ans = 1
for i in range(2, n + 1):
    arr = prime_factorize(i)
    tmp = 1
    for j in arr:
        tmp *= j + 1
    ans += i * tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

maxn = 10000005
spf = [0 for i in range(maxn)] 

def sieve():
    spf[1] = 1
    for i in range(2, maxn):
        spf[i] = i
    for i in range(4, maxn, 2):
        spf[i] = 2
    p = maxn**0.5
    p = int(p)+1
    for i in range(3,p):
        if (spf[i] == i):
            for j in range(i * i, maxn, i):
                if (spf[j] == j):
                    spf[j] = i 

sieve()
n = int(input())
ans = [0 for i in range(n+2)]
for i in range(1,n+1):
    temp = i
    freq = defaultdict(int)
    while temp>1:
        freq[spf[temp]]+=1
        temp = temp//spf[temp]
    cnt = 1
    for x in freq:
        cnt = cnt*(freq[x]+1)
    ans[i] = cnt
f = 0
for i in range(1,n+1):
    f = f+(ans[i]*i)
print(f)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
count1=[c for c in range(N+1)]
count2=[c for c in range(N+1)]

i=2
while i<=N:
    j=1
    while i*j<=N:
        count2[i*j]+=count1[i*j]
        j+=1
    i+=1

print(sum(count2))

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

Submission status: Time Limit Exceeded

Solution code:
def yakusu(k):
    cnt=0
    for i in range(int(k**0.5)):
        if k%(i+1)==0:
            cnt+=1
    if (k**0.5).is_integer():
        return 2*cnt-1
    else:
        return 2*cnt

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

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
cnt = 0
for i in range(1, n+1):
    cnt2 = 0
    for j in range(1, int(math.sqrt(i))+1):
        if i%j == 0:
            if i/j == j:
                cnt2+=1
            else:
                cnt2+=2
    cnt += i*cnt2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    arr = [0] * n

    for i in range(1, int(n**0.5+1)):
        for j in range(i**2, n + 1, i):
            arr[j-1] += 2

    for i in range(1, int(n**0.5+1)):
        arr[i ** 2 - 1] -= 1

    res = 0
    for i, a in enumerate(arr):
       res += (i+1) * a
    print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
INF = 10 ** 7
is_prime = [1] * INF

def eratorasu():
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, INF):
        if is_prime[i] == 0:
            continue
        for j in range(i * 2, INF, i):
            is_prime[j] = 0
    return

eratorasu()
N = int(input())
total = 0
for j in range(1, N + 1):
    cnt = 0
    if is_prime[j] == 1:
        cnt += 1
        if j != 1:
            cnt += 1
    else:
        for i in range(1, int(pow(j, 0.5)) + 1):
            if j % i == 0:
                cnt += 1
                if i != j // i:
                    cnt += 1
    total += cnt * j

print(total)

Submission status: Time Limit Exceeded

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

total = 0
for i in range(1,N+1):
  tmp = []
  for j in range(1,int(i/2)+1):
    if i % j == 0:
      tmp.append(j)
  tmp.append(i)
  total += i*len(tmp)
print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

d = [1]*n

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sum = 0
for i  in range(1, n + 1) :
    sum += i * count_divisors(i)

print(sum)

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]

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

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

print(str(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
def factorization(n):
    arr = []
    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.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
ans=0
for i in range(1,N+1):
  p=factorization(i)
  a=1
  for x,y in p:
    a*=(y+1)
  ans+=a*i
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000000)
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 sum(n):
    if n <= 1:
        return n
    K = n * len(make_divisors(n))
    return K + sum(n-1)
N = int(input())
print(sum(N))

Submission status: Time Limit Exceeded

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

    return divisors

input_num = int(input())
ans = 0
for i in range(1,input_num+1):
    # print(ans)
    ans += i*make_divisors_num(i)

print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
f = [1] * (N+1)
for i in range(2, N+1):
    for j in range(N//i + 1):
        f[i*j] += 1
ans = 0
for i, fk in enumerate(f):
    ans += i*fk
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def num_divisors(a):
  num = 0
  for i in range(1,a+1):
    if a%i==0:num+=1
  return num
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:
a=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]

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