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 itertools
def get_factor(x):
    for i in itertools.chain([2], itertools.count(3, 2)):
        if x<=1: break
        while x%i==0:
            x//=i
            yield i
def f(x):
    factors = list(get_factor(x))
    c = []
    s = 1
    for i in factors:
        if i not in c: c.append(i)
    for num in c:
        s *= factors.count(num)+1
    return s
n = int(input())
s = 0
for k in range(1, n+1): s += k * f(k)
print(s)

Submission status: Time Limit Exceeded

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

n = int(input())

s = 0

for i in range(n):
  s += (i+1) * divisor_count(i+1)
  
print(s)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
#dp = [0]*10**7+1

def fac(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 = 1

for i in range(2, n+1):
    li = fac(i)
    #print(li)
    temp=1
    for j in li:
        temp*=j[-1]+1
    
    ans+=temp*i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

def divisors(n):
    divs = {1,n}
    for i in range(2,int(sqrt(n))+1):
        if n%i == 0:
            divs.update((i,n//i))
    return len(divs)

a=int(input())
ans=0
for j in range(a+1):
    ans=ans+(j*divisors(j))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():

    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
    ans = 0
    for i in range(N):
        ans += (i+1)*divisor_num(i+1)
    print(ans)
resolve()

Submission status: Time Limit Exceeded

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

#     divisors.sort()
    return c
n= int(input())
c=0
for i in range(1,n+1):
    k= i*make_divisors(i)
    c=c+k
print(c)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    if 1==1:
#    if is_p[i]==2:
#      cnt=2
      for j in range(i*2,lim,i):
#        cnt+=1
#        is_p[j] = cnt
        is_p[j] += 1

  return is_p

lim=n+1
is_p=eratosthenes(lim)

#print(is_p)

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

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 (n / i == i) : 
                cnt = cnt + 1
            else :
                cnt = cnt + 2
                  
    return cnt 
        
t = int(input())
ans = 0
for i in range(1,t+1):
    ans = ans + i * countDivisors(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
f=[len(make_divisors(i)) for i in range(1,n+1)]
for i in range(1,n+1):
    ans+=i*f[i-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(raw_input())
mem = {1: 1}
primes = [True] * (n + 1)
posprimes = []
for d in range(2, n +1):
	if primes[d] is True:
		posprimes.append(d)
		k = 2
		while(k * d <= n):
			primes[k * d] = False
			k += 1

def f(k):
	if primes[k] is True:
		mem[k] = 2 if k > 1 else 1
		return mem[k]
	for pos in posprimes:
		if k % pos == 0:
			count = 0
			q = k
			while(q % pos == 0):
				q /= pos
				count += 1

			mem[k] = (count + 1) * (f(q))
			return mem[k]



s = 0
for k in range(1,n+1): s += k * f(k)
print s 




#2 4 6 8 10 12 14 16 18
#    6      12       18

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

d = np.ones(n)

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

print(int(sum(d)))

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 = input()
s = 0
for nn in range(int(n)):
    s += (nn+1)*(len(make_divisors(int(nn+1))))
print(s)

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

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

N = int(input().rstrip())
d = {}
answer = 0
for a in range(1, N+1):
    answer += a * len(make_divisors(a))
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

if 1 <= N <= 10**7:
    for i in range(1,N+1):
        fN = len(make_divisors(i))
        a += i * fN
    
    

print(a)

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[::-1])


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:
from math import sqrt


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; 


def main():
    n=int(input())
    a=0
    for k in range(1, n+1):
        a+=k*f(k)
    print(a)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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


from collections import defaultdict, deque
from heapq import heappush, heapreplace
from itertools import count
from math import ceil, sqrt

class Primes_C(object):
    """以下のmodule依存
    from collections import defaultdict, deque
    from heapq import heappush, heapreplace
    from itertools import count
    from math import ceil, sqrt
    """

    def b_search(L,t):
        #増大列LについてL[:+1]の要素すべてがt以下であるような最大のi<len(L)を返す。
        search_range = [-1, len(L)]
        update_range = lambda mid: search_range.__setitem__(t<L[mid], mid)
        for _ in range(search_range[1].bit_length()):
            update_range(sum(search_range)//2)
        return search_range[0]
    
    def __init__(self):
        self.P = [2]
        self.Pappend = self.P.append
        self.Q = deque([])
        self.Qappend = self.Q.append
        self.Qpopleft = self.Q.popleft
        self.hq = [] 
        self.integer = count(3,2)
        self.current_i = 2
        self.valid_range = 1
        self.iter_index = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.iter_index >= len(self.P):
            self.step_calc(1)
        self.iter_index += 1
        return self.P[self.iter_index-1]

    def iter_reset(self, index=0):
        self.iter_index = index

    def list(self, max_int=None):
        if max_int is None:
            return self.P[:]

        elif  max_int <= self.current_i:
            return self.P[:Primes_C.b_search(self.P,max_int)+1]

        else:
            self.calc(max_int)
            return self.P[:]

    def extend(self, i):
        if i >= self.valid_range:
            if self.Q:
                q = self.Qpopleft()
                heappush(self.hq, (q**2,q))
            self.valid_range = self.Q[0]**2 if self.Q else i**2

    def check_update(self,i):
        m,r = self.hq[0] if self.hq else (0,0)
        flag =  (i != m)
        if flag:
            self.Pappend(i)
            self.Qappend(i)
        while m == i:
            heapreplace(self.hq, (m+2*r, r))
            m,r = self.hq[0]
        return flag

    def calc(self, max_int):
        for i in self.integer:
            self.extend(i)
            self.check_update(i) 
            self.current_i = i+1
            if max_int <= self.current_i:
                break

    def step_calc(self, step):
        for i in self.integer:
            self.extend(i)
            step -= self.check_update(i) 
            self.current_i = i+1
            if not step:
                break

    def factorization(self, m, F=defaultdict(int), break_flag=False):
        if m <= 0:
            raise  ValueError('m >= 1')
        iter_index = self.iter_index
        self.iter_reset()
        flag = True
        for p in self:
            if flag:
                try:
                    max_int = ceil(sqrt(m))
                except OverflowError:
                    max_int = m//p

                flag = False
            if m >= p > max_int:
                F[m] += 1
                break
            while not m%p:
                m //= p
                F[p] += 1
                flag = True
            if (flag and break_flag) or m == 1:
                break
        F_ = dict(F)
        F.clear()
        self.iter_reset(iter_index)
        return F_

    def count_divisors(self, m=None, F=None):
        if F is None:
            if m is not None:
                F = self.factorization(m)
            else:
                raise ValueError 
        c = 1
        for l in F.values():
            c *= l+1
        return c

    def is_prime(self, m, witness=False):
        F = self.factorization(m, break_flag=True)
        if witness:
            if m in F or m <= 1:
                return False
            else:
                return list(F.keys())[0]
        else:
            return m in F


def solve():
    N = int(input())
    P = Primes_C()
    P.calc(ceil(sqrt(N)))
    F = {i:dict() for i in range(1,N+1)}
    for i in range(2,N+1):
        if (w := P.is_prime(i, witness=True)):
            F[i].update(F[i//w])
            if w in F[i]:
                F[i][w] += 1
            else:
                F[i][w] = 1
        else:
            F[i][i] = 1
    c = sum(i*P.count_divisors(F=F[i]) for i in range(1,N+1))
    return str(c)

if __name__ == '__main__':
    print(solve())

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
# import sympy

def func(k):
    i = 1
    cnt = 0
    if k == 1:
        return 1
    while i*i <= k:
        if k % i == 0:
            cnt += 1
            if i != k // i:
                cnt += 1
        i += 1
    return cnt

n = int(input())
sum = 0
for i in range(1, n + 1):
    # sum += i * sympy.divisor_count(i)
    sum += i * func(i)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# cook your dish here
N=int(input())
summ=0
def divCount(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
for i in range(1,N+1):
    summ+=i*divCount(i)
# print(divCount(3))
print(summ)

Submission status: Time Limit Exceeded

Solution code:
#26879
N = int(input())

def find_count_of_divisor(n):
  count = 0
  for i in range(1, n+1):
    i_square = i*i
    if i_square > n:
      break
    elif i_square == n:
      count += 1
    elif not n%i:
      count += 2
  return count

if N <= 3:
  answer = 0
  f = [1, 2, 2]
  for k in range(1, N+1):
    answer += k * f[k-1]
  print(answer)
    
else:
  answer = 11
  for k in range(4, N+1):
    answer += (k * find_count_of_divisor(k))
  print(answer)

Submission status: Time Limit Exceeded

Solution code:
def factorize(n):
    fct=[]
    b,e=2,0
    while b*b<=n:
        while n%b==0:
            n=n//b
            e=e+1
        if e>0:
            fct.append((b,e))
        b,e=b+1,0
    if n>1:
        fct.append((n,1))
    return fct

def d(n):
    l=factorize(n)
    r=1
    for i,j in l:
        r*=int(j)+1
    return r

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    res = np.zeros(n, dtype="int")

    def rec(x):
        if x == 1:
            res[x - 1] = 1

        elif res[x - 1] == 0:
            tmp = factorization(x)
            p = 1

            for t in tmp[::-1]:
                if res[x // t[0] - 1] == 0:
                    rec(x // t[0])

                p *= (t[1] + 1)

            res[x - 1] = p

    for i in range(n, 0, -1):
        rec(i)

    res = sum(res * np.arange(1, n + 1))
    return res

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

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cout = main(kwargs)
    print(cout)

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]
a = int(input())
c = 0
for i in range (0,a+1):
    b = make_divisors(i)
    c = c + i * len(b)
print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
def devv(n):
	i=1
	count=0
	while i<=math.sqrt(n):
		if n%i==0:
			if (n//i)==i:
				count=count+1
			else:
				count=count+2
		i=i+1
	return count

t=int(input())
j=1
Sum=0
while j<=t:
	Sum=Sum+(j*devv(j))
	j=j+1
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
n=int(input())+1
yueg=[0]*(n)
for i in range(1,n):
  j=0
  while j < n:
    yueg[j]+=1
    j+=i
  yueg[i]*=i
r=0  
#yueg=np.array(yueg)
#ka=np.array([k for k in range(0,n)])
#r=np.sum(yueg*ka)
print(sum(yueg)-yueg[0])

Submission status: Time Limit Exceeded

Solution code:
import math

def prime(n):
    prime = {}
    max = int(math.sqrt(n)) + 1
    for i in range(2, max):
        while n % i == 0:
            n = n / i
            if not i in prime.keys():
                prime[i] = 1
            else:
                prime[i] += 1
    if n > 1:
        prime[n] = 1
    return prime

def f(n):
    factors = prime(n)
    if len(factors.keys()) == 0 and n == 1:
        return 1
    count = 0
    for k, v in factors.items():
        if count == 0:
            count = v + 1
        else:
            count = count * (v + 1)
    return count

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

def fac(n):
    f = []
    c = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            #f.append(i)
            c += 1
            if i != n // i:
                #f.append(n//i)
                c += 1
    return c*n

result = 0
for i in range(1,n+1):
  result += fac(i)
print(result)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
K = 1
total = 0

while K <= N :
  yakusu = [i for i in range(1,K+1) if K % i == 0]
  yakusu_len = len(yakusu)
  total += yakusu_len * K
  K += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
import heapq

N = int(input())

def f(N):
    if N<=2:
        return N
    ans = [1, N]
    heapq.heapify(ans)
    for i in range(2, math.ceil(N**0.5)+1):
        if N%i == 0:
            heapq.heappush(ans, i)
            if i*i != N:
                heapq.heappush(ans, N//i)
    return len(set(ans))

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

def count_divisors(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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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())
ans = 0
for j in range(N):
    n = j + 1
    if n == 1:
        ans += 1
    elif is_prime(n):
        ans += n*2 
    else:
        ans += n*make_divisors(n)
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]
  
def main():
  n = int(input())
  sum=0
  for i in range(1,n+1):
    sum+=i*len(make_divisors(i))
  print(sum)
main()

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

s=0
ans=0
for k in range(1,N+1):
    s=len(divisor(k))
    ans+=k*s
    
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections


def a_prime_factor_table(n):
    table = [0] * (n + 1)

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

    return table


def prime_factor(n, prime_factor_table):
    prime_count = collections.Counter()

    while prime_factor_table[n] != 0:
        prime_count[prime_factor_table[n]] += 1
        n //= prime_factor_table[n]
    prime_count[n] += 1

    return prime_count

def num_divisors(prime_count):
    num = 1

    for prime, count in prime_count.items():
        num *= (count + 1)

    return num

N = int(input())
ans = 0
table = a_prime_factor_table(N)
for num in range(1,N+1):
    if num == 1:
        ans += 1
        continue
    a = prime_factor(num,table)

    ans += num*num_divisors(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

table = [0] * (n + 1)

res = 0

for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        table[j] += 1
    table[i] = table[i]*i
    res += table[i]

print(res)

Submission status: Time Limit Exceeded

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

n = int(input())
dp = [1]*(n+1)
res = 0

for i in range(2, n+1):
    for j in range(1, (n//i)+1):
        dp[i*j] += 1



for i in range(1, n+1):
    res += i*dp[i]

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
import collections

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

con = 0;
for k in range(1,n+1):
    c = collections.Counter(prime_factorize(k))
    x = list(c.values())
    y = len(x);
    kk = k
    for p in range(y):
        kk = kk*(x[p]+1)
    
    con += kk;
        
print(con);

Submission status: Time Limit Exceeded

Solution code:
import math
def factorization(num):
    factor = []
    flag = True
    is_Prime= True
    if num == 1:
        is_Prime = False
    while num > 1 and flag:
        flag = False
        for i in range(int(math.sqrt(num))+2):
            k = i + 2
            if num % k == 0:
                factor.append(k)
                num = int(num / k)
                is_Prime = False
                flag = True
                break
    if is_Prime or num > 1:
        factor.append(num)
    return factor

from collections import Counter

n = int(input())
result = 0
for k in range(1, n+1):
    f_k = factorization(k)
    co_f_k = Counter(f_k)
    fk = 1
    for item in co_f_k.values():
        fk *= item+1
    result += k * fk


print(result)

Submission status: Time Limit Exceeded

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

import math
n=int(input())
ans=0
for i in range(1, n+1):
    ans+=divCount(i)*i
    # print(i,divCount(i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections


a = int(input())
count = 0


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
for i in range(1, a + 1):
  c = collections.Counter(prime_factorize(i))
  m=list(c.values())
  count1=1
  for j in m :
    count1*=(j+1)
  count += i*count1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
count=0
A=[]
for K in range(1,N+1):
    for i in range(1,K+1):
        if K%i==0 :
            count+=1
    else:
        x=K*count
        A.append(x)
        count=0
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=0
for i in range(1,n+1):
    a=i
    for j in range(2,1+int(i**.5)):
        b=0
        while i%j==0:
            i//=j
            b+=1
        a*=b+1
    if i!=1:
        a*=2
    ans+=a
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
count = 0
for i in range(1, (N+1)):
    count += i * len(divisor(i))

print(count)

Submission status: Time Limit Exceeded

Solution code:
X=int(input())

def factorization(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
  
answer=0
for k in range(1,X+1):
  answer+= k*factorization(k)
  
print(answer)

Submission status: Time Limit Exceeded

Solution code:

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

  table = [1]*(N+1)
  for i in range(2, N+1):
    n = i
    while n <= N:
      table[n] += 1
      n += i

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

  print(ans)

if __name__ == "__main__":
  resolve()

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
ans = 0
def f(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


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=0
for i in range(1,n+1):
    t=0
    for j in range(1,int((i+1)**(1/2))+1):
        if i%j==0:
            t+=1
    t=t*2
    if i==(int((i+1)**(1/2)))**2:
        t+=-1
    s+=i*t
print(s)

Submission status: Time Limit Exceeded

Solution code:
record = [0]*20000000
N = int(input())


nums = []
for n in range(1,N+1):
    nums.append(int(N/n))
# print(nums)

ro = 1
for num in nums:
    # print(num)
    for j in range(1,num+1):
        # print(j*ro)
        record[j*ro] += 1
    # print('---')
    ro += 1
    

sum = 0
for r in range(len(record)):
    sum += r*record[r]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(N):
    div = np.zeros(N+1, np.int64)
    for n in range(1, N+1):
      div[::n] += 1
    div *= np.arange(N + 1)
    return div.sum()

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8, ))
    cc.compile()

from my_module import main

N = int(read())
print(main(N))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def is_prime(N):
    i = 2
    table = []
    while i*i <= N:
        while N%i == 0:
            N //= i
            table.append(i)
        i += 1
    if N > 1:
        table.append(N)
    return table

N = int(input())
ans = 0
for i in range(1, N+1):
    C = Counter(is_prime(i))
    cnt = 1
    if not C.values():
        cnt = 1
    for c in C.values():
        cnt *= (c + 1)
    ans += i * cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
def f(n) : 
    c=0
    for i in range(1,(int)(math.sqrt(n))+1) : 
        if (n % i == 0) : 
            if (n / i == i) : 
                c=c+1
            else:
                c=c+2
    return c 
    
n=int(input())
s=0
for k in range(1,n+1):
    s+=k*f(k)
print(s)