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:
# Python3 program to count distinct
# divisors of a given number n


def SieveOfEratosthenes(n, prime, primesquare, a):
    # Create a boolean array "prime[0..n]"
    # and initialize all entries it as
    # true. A value in prime[i] will finally
    # be false if i is not a prime, else true.
    for i in range(2, n+1):
        prime[i] = True

    # Create a boolean array "primesquare[0..n*n+1]"
    # and initialize all entries it as false.
    # A value in squareprime[i] will finally be
    # true if i is square of prime, else false.
    for i in range((n * n + 1)+1):
        primesquare[i] = False

    # 1 is not a prime number
    prime[1] = False

    p = 2
    while(p * p <= n):
        # If prime[p] is not changed,
        # then it is a prime
        if (prime[p] == True):
            # Update all multiples of p
            i = p * 2
            while(i <= n):
                prime[i] = False
                i += p
        p += 1

    j = 0
    for p in range(2, n+1):
        if (prime[p] == True):
            # Storing primes in an array
            a[j] = p

            # Update value in primesquare[p*p],
            # if p is prime.
            primesquare[p * p] = True
            j += 1

# Function to count divisors


def countDivisors(n):
    # If number is 1, then it will
    # have only 1 as a factor. So,
    # total factors will be 1.
    if (n == 1):
        return 1

    prime = [False]*(n + 2)
    primesquare = [False]*(n * n + 2)

    # for storing primes upto n
    a = [0]*n

    # Calling SieveOfEratosthenes to
    # store prime factors of n and to
    # store square of prime factors of n
    SieveOfEratosthenes(n, prime, primesquare, a)


    ans = 1

    i = 0
    while(1):
        if(a[i] * a[i] * a[i] > n):
            break

        cnt = 1  # cnt is power of
        # prime a[i] in n.
        while (n % a[i] == 0):  
            n = n / a[i]
            cnt = cnt + 1  

    
        ans = ans * cnt
        i += 1


    n = int(n)
    # First case
    if (prime[n] == True):
        ans = ans * 2

    elif (primesquare[n] == True):
        ans = ans * 3


    elif (n != 1):
        ans = ans * 4

    return ans  

n=int(input())
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 python
# coding: utf-8

# In[26]:


N = int(input())


# In[29]:


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


# In[30]:


print(sum(k*len(make_divisors(k)) for k in range(1,N+1)))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
def yakusu(x):
    
    if x == 1:
        yaku = 1
    else:
        yaku = 2
        for i in range(2,x//2 + 1):
            if x % i == 0:
                yaku += 1
    
    return yaku

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

print(count)

Submission status: Time Limit Exceeded

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

# In[26]:


N = int(input())


# In[27]:


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]


# In[28]:


print(sum(k*len(make_divisors(k)) for k in range(1,N+1)))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def make_divisors(n):
    divisors = 0
    for i in range(1, int(pow(n,0.5)+1)):
        if n%i==0:
            divisors += 1
            if i!=n//i: 
                divisors += 1
    return divisors

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

Submission status: Time Limit Exceeded

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

  numlist=prime_factorize(n)
  
  yakusuu_num=1
  while numlist:
    now=numlist[0]
    #print("now="+str(now))
    count=numlist.count(now)
    #print("count="+str(count))
    while now in numlist:
      numlist.remove(now)
      #print(str(now)+"を削除")
    yakusuu_num=yakusuu_num*(count+1)
    #print(yakusuu_num)
  
  return yakusuu_num
    
    
N=int(input())


newans=0
for i in range(1,N+1):
  newans+=i*yaku_num(i)
print(newans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

#素因数分解O(√n)
def primeFactor(n):
    res = defaultdict(lambda: 0)
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            res[i] += 1
            n = n // i
    if n != 1:
        res[n] = 1
    return res

N = int(input())

ans = 0
for i in range(1, N+1):
    d = primeFactor(i)
    if d == {}:
        p = 1
    else:
        p = 1
        for v in d.values():
            p *= (v+1)
    ans += i*p

print(ans)

Submission status: Time Limit Exceeded

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

furui = np.zeros(N+1, dtype=float)
for i in range(1, N+1):
    furui[i::i] = furui[i::i]+1

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

print(int(furui.sum()))

Submission status: Time Limit Exceeded

Solution code:

N=int(input())
ans=0

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

for i in range(1,N+1):
	ans+=make_divisors(i)*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]

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 num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

N = int(input())
res = 0
data = num_divisors_table(N)

for i in range(1,N+1):
    num = i * data[i]
    res += num

print(res)

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
def make_divisors(n):
    #divisors = []
    count = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            #divisors.append(i)
            count = count+1
            if i != n // i:
                #divisors.append(n//i)
                count = count + 1

    #divisors.sort()
    return count


count = 0
N = int(input())

for i in range(N):

    count = count + (i+1) * make_divisors(i+1)

print(count)

Submission status: Time Limit Exceeded

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

n = int(input())

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

F = [0] * (n+1)

for i in range(2, n+1):
    
    
    if F[i] == 0:
        for j in range(i, n+1, i):
            F[j] = 1
        # L = [0] * (n+1)
        L = {}
        m = i
        while m <= n:
            # print("m",m)
            for j in range(m, n+1, m):
                try:
                    L[j] += 1
                except:
                    L[j] = 1
            m *= i
        # print(L)
        for j in L.keys():
            A[j] *= L[j]+1
# print(A)
# print(A[24])
ans = 0
for i in range(n+1):
    ans += i * A[i]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ans=0
def f(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):
    ans+=i*(len(f(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
      
def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        ans += i * num_divisors_trial_division(i)
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math


# function to count the divisors
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())
s=0
for i in range(1,n+1):
	s+=(i*countDivisors(i))
	
print(s)

Submission status: Time Limit Exceeded

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


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
total=0
def divisors_count(s):
  count=0
  if s==1:
    return 1
  elif s==2:
    return 2
  
  for i in range(1,int(s/2)+1):
    if s%i==0:
      count+=1
  return count+1
for i in range(1,N+1):
  total=total+i*divisors_count(i)
  #print(i, divisors_count(i))
  #print(total,"total")
print(total)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
def p(a):print(" ".join(list(map(str,a))))
from collections import Counter

def SieveOfEratosthenes(n, prime,primesquare, a): 
    # Create a boolean array "prime[0..n]"  
    # and initialize all entries it as  
    # true. A value in prime[i] will finally  
    # be false if i is not a prime, else true. 
    for i in range(2,n+1): 
        prime[i] = True
  
    # Create a boolean array "primesquare[0..n*n+1]" 
    # and initialize all entries it as false.  
    # A value in squareprime[i] will finally be  
    # true if i is square of prime, else false. 
    for i in range((n * n + 1)+1): 
        primesquare[i] = False
  
    # 1 is not a prime number 
    prime[1] = False
  
    p = 2
    while(p * p <= n): 
        # If prime[p] is not changed,  
        # then it is a prime 
        if (prime[p] == True): 
            # Update all multiples of p 
            i = p * 2 
            while(i <= n): 
                prime[i] = False
                i += p 
        p+=1
      
  
    j = 0
    for p in range(2,n+1):  
        if (prime[p]==True):  
            # Storing primes in an array 
            a[j] = p 
  
            # Update value in primesquare[p*p], 
            # if p is prime. 
            primesquare[p * p] = True
            j+=1
  
# Function to count divisors 
def countDivisors(n): 
    # If number is 1, then it will 
    # have only 1 as a factor. So, 
    # total factors will be 1. 
    if (n == 1): 
        return 1
  
    prime = [False]*(n + 2) 
    primesquare = [False]*(n * n + 2) 
      
    # for storing primes upto n 
    a = [0]*n 
  
    # Calling SieveOfEratosthenes to  
    # store prime factors of n and to  
    # store square of prime factors of n 
    SieveOfEratosthenes(n, prime, primesquare, a) 
  
    # ans will contain total 
    # number of distinct divisors 
    ans = 1
  
    # Loop for counting factors of n 
    i=0
    while(1):  
        # a[i] is not less than cube root n 
        if(a[i] * a[i] * a[i] > n): 
            break
  
        # Calculating power of a[i] in n. 
        cnt = 1 # cnt is power of  
                # prime a[i] in n. 
        while (n % a[i] == 0): # if a[i] is a factor of n 
            n = n / a[i] 
            cnt = cnt + 1 # incrementing power 
  
        # Calculating number of divisors 
        # If n = a^p * b^q then total  
        # divisors of n are (p+1)*(q+1) 
        ans = ans * cnt 
        i+=1
  
    # if a[i] is greater than 
    # cube root of n 
      
    n=int(n) 
    # First case 
    if (prime[n]==True): 
        ans = ans * 2
  
    # Second case 
    elif (primesquare[n]==True): 
        ans = ans * 3
  
    # Third casse 
    elif (n != 1): 
        ans = ans * 4
  
    return ans
n=IN()
ans=0
for i in range(1,n+1):
    ans+=i*countDivisors(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict
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:
from collections import defaultdict
n = int(input())


def sieve(n):
    n += 1
    res = [i for i in range(n)]
    for p in range(2, int(n**.5)+1):
        if res[p] < p:
            continue
        for q in range(p**2, n, p):
            if res[q] == q:
                res[q] = p
    return res


U = 10**7
min_factor = sieve(U)


def prime_factor(n):
    res = defaultdict(int)
    while 1 < n:
        res[min_factor[n]] += 1
        n //= min_factor[n]
    return res


ans = 0
for i in range(1, n+1):
    x = 1
    for v in prime_factor(i).values():
        x *= v+1
    ans += x*i


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

Submission status: Time Limit Exceeded

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

def divisor_num(n, board):
    for i in range(2, n+1):
        j = 1
        while i*j <= n:
            board[i*j] += 1
            j += 1

divisor_num(n, board)
res = sum([i * board[i] for i in range(1, n+1)])
print(res)

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 len(lower_divisors + upper_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 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(sympy.divisors(i))
    ans+= i*len(make_divisors(i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def divisors(n):
    count=0
    for i in range (1,n+1):
        if (n%i == 0):
            count+=1

    return count 
    

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

N_list = [0] * (N + 1)

for n in range(N + 1):
    if n == 0:
        continue
    else:
        for i in range(n, N + 1, n):
            #print(i)
            N_list[i] += 1

sum = 0
for n in range(N + 1):
    sum += n * N_list[n]
#print(N_list)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dp = [0 for i in range(n+1)]
ans = 1
for i in range(2,n+1):
    cnt = 2
    for j in range(2,i//2+1):
        if i%j==0:
            cnt+=1
    ans += i*cnt
    #print(cnt)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 1

for K in range(2, N + 1):
    array = factorization(K)
    yakusu_num = 1
    for a in array:
        yakusu_num = yakusu_num * (a[1] + 1)

    ans += K * yakusu_num


print(ans)

Submission status: Time Limit Exceeded

Solution code:
def count_divisors(n):
    cnt = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            cnt += 1
            if i != n // i:
                cnt += 1
        i += 1
    return cnt
N = int(input())
ans = 0
for i in range(1,N+1):
  ans += i * count_divisors(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
    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:
n = int(input())
res = 0
import math
def divisors(n):
    divs = [1]
    for i in range(2,int(math.sqrt(n))+1):
        if n%i == 0:
            divs.extend([i,n/i])
    divs.extend([n])
    return len(list(set(divs)))
  
for i in range(1,n+1):
    res += i * divisors(i)
print(res)

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def solve():
    factors = [1]*(n+1)
    ans = 1
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            factors[j] += 1
        ans += (factors[i]*i)
    return ans

if __name__ == '__main__':
    n = int(input())
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): 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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

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 = ii()
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 divisor(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 

total = 0
for i in range(n):
  total += (n-i)*len(divisor(n-i))
  
print(total)

Submission status: Time Limit Exceeded

Solution code:
from math import floor
from collections import defaultdict


def Calc_Divisors(num):
    divisors = []
    for i in range(1, int(sqrt(num)) + 1):
        if num % i == 0:
            divisors.append(i)
            if i != num // i:
                divisors.append(num//i)
    # divisors.sort()
    return divisors


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

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

    print(int(ans))


def test():
    ans = 0
    for i in range(1, 10000000):
        d = Calc_Divisors(i)
        print(len(d))
        ans += len(d) * i
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:


def SieveOfEratosthenes(n, prime, primesquare, a):
    # Create a boolean array "prime[0..n]"
    # and initialize all entries it as
    # true. A value in prime[i] will finally
    # be false if i is not a prime, else true.
    for i in range(2, n + 1):
        prime[i] = True

    # Create a boolean array "primesquare[0..n*n+1]"
    # and initialize all entries it as false.
    # A value in squareprime[i] will finally be
    # true if i is square of prime, else false.
    for i in range((n * n + 1) + 1):
        primesquare[i] = False

    # 1 is not a prime number
    prime[1] = False

    p = 2
    while (p * p <= n):
        # If prime[p] is not changed,
        # then it is a prime
        if (prime[p] == True):
            # Update all multiples of p
            i = p * 2
            while (i <= n):
                prime[i] = False
                i += p
        p += 1

    j = 0
    for p in range(2, n + 1):
        if (prime[p] == True):
            # Storing primes in an array
            a[j] = p

            # Update value in primesquare[p*p],
            # if p is prime.
            primesquare[p * p] = True
            j += 1


# Function to count divisors
def countDivisors(n):
    # If number is 1, then it will
    # have only 1 as a factor. So,
    # total factors will be 1.
    if (n == 1):
        return 1

    prime = [False] * (n + 2)
    primesquare = [False] * (n * n + 2)

    # for storing primes upto n
    a = [0] * n

    # Calling SieveOfEratosthenes to
    # store prime factors of n and to
    # store square of prime factors of n
    SieveOfEratosthenes(n, prime, primesquare, a)

    # ans will contain total
    # number of distinct divisors
    ans = 1

    # Loop for counting factors of n
    i = 0
    while (1):
        # a[i] is not less than cube root n
        if (a[i] * a[i] * a[i] > n):
            break

        # Calculating power of a[i] in n.
        cnt = 1  # cnt is power of
        # prime a[i] in n.
        while (n % a[i] == 0):  # if a[i] is a factor of n
            n = n / a[i]
            cnt = cnt + 1  # incrementing power

        # Calculating number of divisors
        # If n = a^p * b^q then total
        # divisors of n are (p+1)*(q+1)
        ans = ans * cnt
        i += 1

    # if a[i] is greater than
    # cube root of n

    n = int(n)
    # First case
    if (prime[n] == True):
        ans = ans * 2

    # Second case
    elif (primesquare[n] == True):
        ans = ans * 3

    # Third casse
    elif (n != 1):
        ans = ans * 4

    return ans  # Total divisors


# Driver Code
if __name__ == '__main__':
    m=0
    for i in range(int(input())):
        m+=(i+1)*(countDivisors(i+1))
    print(m)

Submission status: Time Limit Exceeded

Solution code:
import math,bisect,collections
n=int(input())
def divisor(n):
    ans=[]
    for i in range(1,int(math.sqrt(n))+1):
        if n%i==0:
            if i!=n//i:
                ans.append(i)
                ans.append(n//i)
            else:
                ans.append(i)
    return len(ans)
x=0
for i in range(1,n+1):
    #print(i,divisor(i))
    x+=i*divisor(i)
#print("Hello")
print(x)

Submission status: Time Limit Exceeded

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

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

    sum_data=0

    for i in range(1,n+1):
        x=make_divisors(i)
        sum_data=x*i+sum_data

    print(sum_data)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
def make_prime_list_2(num):
    if num < 2:
        return []

  
    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().strip())
x=0
for i in range(N):
    x+=search_divisor_num_1(i+1)*(i+1)
print(x)

Submission status: Time Limit Exceeded

Solution code:
#ABC172-D

def calc(x):
    a=0
    p=floor(x**0.5)
    cnt=0
    for i in range(1,p+1):
        if x%i==0:
            if i!=x//i:
                cnt +=2
            else:
                cnt +=1
    return cnt

from math import floor
N=int(input())
ans=0
for i in range(1,N+1):
    #print(i,calc(i))
    ans += i*calc(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def Primefactors(N):# Nより小さい自然数の素因数の個数と約数の個数を返すO(Nlog(N))
    Ints = [ i for i in range(N)]
    # Primefactors = [0]*N
    Factors = [1]*N
    for i in range(2, N):
        if Ints[i] == 1:
            continue
        for j in range(1, N):
            if i*j < N:
                t = 1
                while Ints[i*j]%i == 0:
                    Ints[i*j] //= i
                    # Primefactors[i*j] += 1
                    t += 1
                Factors[i*j] *= t
            else:
                break
    return Factors

def main():
    N = int( input())
    F = Primefactors(N+1)
    # print(F)
    ans = 0
    for i in range(1,N+1):
        ans += i*F[i]
    print(ans)
if __name__ == '__main__':
    main()