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

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

Submission status: Time Limit Exceeded

Solution code:
# Python3 program to count 
# number of factors 
# of an array of integers 
MAX = 10000001; 

# array to store 
# prime factors 
factor = [0]*(MAX + 1); 

# function to generate all 
# prime factors of numbers 
# from 1 to 10^6 
def generatePrimeFactors(): 
	factor[1] = 1; 

	# Initializes all the 
	# positions with their value. 
	for i in range(2,MAX): 
		factor[i] = i; 

	# Initializes all 
	# multiples of 2 with 2 
	for i in range(4,MAX,2): 
		factor[i] = 2; 

	# A modified version of 
	# Sieve of Eratosthenes 
	# to store the smallest 
	# prime factor that divides 
	# every number. 
	i = 3; 
	while(i * i < MAX): 
		# check if it has 
		# no prime factor. 
		if (factor[i] == i): 
			# Initializes of j 
			# starting from i*i 
			j = i * i; 
			while(j < MAX): 
				# if it has no prime factor 
				# before, then stores the 
				# smallest prime divisor 
				if (factor[j] == j): 
					factor[j] = i; 
				j += i; 
		i+=1; 

# function to calculate 
# number of factors 
def calculateNoOFactors(n): 
	if (n == 1): 
		return 1; 
	ans = 1; 

	# stores the smallest 
	# prime number that 
	# divides n 
	dup = factor[n]; 

	# stores the count of 
	# number of times a 
	# prime number divides n. 
	c = 1; 

	# reduces to the next 
	# number after prime 
	# factorization of n 
	j = int(n / factor[n]); 

	# false when prime 
	# factorization is done 
	while (j > 1): 
		# if the same prime 
		# number is dividing 
		# n, then we increase 
		# the count 
		if (factor[j] == dup): 
			c += 1; 

		# if its a new prime factor 
		# that is factorizing n, 
		# then we again set c=1 and 
		# change dup to the new prime 
		# factor, and apply the formula 
		# explained above. 
		else: 
			dup = factor[j]; 
			ans = ans * (c + 1); 
			c = 1; 

		# prime factorizes 
		# a number 
		j = int(j / factor[j]); 

	# for the last 
	# prime factor 
	ans = ans * (c + 1); 

	return ans; 



n=int(input())

generatePrimeFactors()
ans=0
for i in range(1,n+1):
    ans+=calculateNoOFactors(i)*i
    


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
f=[1]*(n+1)
s=1
for c in range(2,n+1):
    for d in range(1,n//c+1):
        f[c*d]+=1
    s+=c*f[c]
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

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

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

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

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

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

prime_list = make_prime_list_2(N+1)
print(sum(k*search_divisor_num_1(k) for  k in range(1,N+1)) )

Submission status: Time Limit Exceeded

Solution code:
def primefactorize(n) :
    res = []
    if n == 1:
        res.append((1,0))
    if n%2 == 0 :
        t = 0
        while n%2 == 0 :
            n //= 2
            t += 1
        res.append((2,t))
    for i in range(3, int(n**0.5)+1, 2) :
        if n%i != 0 :
            continue
        t = 0
        while n%i == 0 :
            n //= i
            t += 1
        res.append((i,t))
        if n == 1 :
            break
    if n != 1 :
        res.append((n,1))
    return res


n = int(input())
f = [1]*n
s = 0

for i in range(1,n+1):
    for p, e in primefactorize(i):
        p = 0
        f[i-1] *= (e+1)

for k in range(1,n+1):
    s += k*f[k-1]

print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def main():
    N = NI()
    # P = primes(N)
    # D = [1] * (N+1)
    # for p in P:
    #     for i in range(1, N//p + 100):
    #         d = p * i
    #         if d > N:
    #             break
    #
    #         tmp = 0
    #         while d % p == 0:
    #             tmp += 1
    #             d = d // p
    #         D[p*i] *= tmp + 1
    ans = 1
    for i in range(2, N+1):
        pf = prime_fact(i)
        tmp = 1
        for a, b in pf.items():
            tmp *= b+1
        ans += tmp * i

    print(ans)


if __name__ == "__main__":
    main()

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

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

Submission status: Time Limit Exceeded

Solution code:
def ss(n):
    s = 1
    for i in range(1,(n//2) + 1):
        if n % i == 0:
            s += 1
    return(s)

n = int(input())
answer = int(0)

for i in range(n+1):
    c = ss(i)
    answer += int(c * i)


print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from functools import reduce
from copy import deepcopy
N = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973]
factors = {1: {}}
for p in primes:
    factors[p] = {p: 1}


def count_factors(K):
    if K in factors:
        return reduce(lambda x, y: x * (y+1), factors[K].values(), 1)
    for p in primes:
        if K % p == 0:
            f1 = factors[p]
            f2 = factors[K // p]
            f = deepcopy(f1)
            for k, v in f2.items():
                f[k] = f1.get(k, 0) + v
            factors[K] = f
            return reduce(lambda x, y: x * (y + 1), f.values(), 1)
    factors[K] = {K: 1}
    return 2


total = 1
for k in range(2, N + 1):
    total += k * count_factors(k)

print(total)

Submission status: Time Limit Exceeded

Solution code:

"""
n,m,k = map(int, input().split())

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))


book_num = 0
time = 0
a = 0
b = 0
for i in range(n+m):
  if a_list == []:
    time += b_list[0]
    if time > k:
      break
    b_list.pop(0)
    book_num += 1

  elif b_list == []:
    time += a_list[0]
    if time > k:
      break
    a_list.pop(0)
    book_num += 1


  elif a_list[0] <= b_list[0]:
    time += a_list[0]
    if time > k:
      break
    a_list.pop(0)
    book_num += 1
  elif a_list == []:
    time += b_list[0]
    if time > k:
      break
    b_list.pop(0)
    book_num += 1

  else:
    time += b_list[0]
    if time > k:
      break
    b_list.pop(0)
    book_num += 1

print(book_num)
"""
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 = 0
for i in range(n+1):
  if i == 0:
    continue
  elif i == 1:
    ans += 1
  else:  
    soinsu = factorization(i)
    f = 1 
    for number in soinsu:
      f *= number[1] + 1
    ans += i * f
    
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def divisor(n):  # nの約数を全て求める
    i = 1
    table =0
    while i * i <= n:
        if n % i == 0:
            table+=2
            if i==n//i:
                table-=1
        i += 1
    
    return table
n = int(input().strip())

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

is_prime = [True] * (N + 1)
is_prime[0] = False
is_prime[1] = False
min_prime=[i for i in range(N+1)]

for i in range(2, int(N**0.5) + 1):
    if not is_prime[i]:
        continue
    for j in range(i * 2, N + 1, i):
        is_prime[j] = False
        min_prime[j]=min_prime[i]

ans=0

for i in range(1,N+1):
    j=i
    dic={}
    while j>1:
        if min_prime[j] in dic:
            dic[min_prime[j]]+=1
        else:
            dic[min_prime[j]]=1
        
        j//=min_prime[j]
    
    cnt=1
    for d in dic.values():
        cnt*=(d+1)
    
    ans+=i*cnt

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

def f(x):
  fact = factorization(x)
  count = 1
  for i in range(len(fact)):
    count *= (fact[i][1]+1)
  return count

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

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict


def prime_factorize(n):
    """素因数分解する。"""
    def facs():
        """試し割り法における割る数を生成する。"""
        yield 2
        max_prime = int(pow(n, 0.5)) + 1
        for x in range(3, max_prime, 2):
            yield x

    ans = defaultdict(int)
    for fac in facs():
        while n % fac == 0:
            ans[fac] += 1
            n //= fac
        if pow(fac, 2) > n:
            break
    if n != 1:
        ans[n] += 1
    return ans


def count_divs(x):
    di = prime_factorize(x)
    ans = 1
    for exp in di.values():
        ans *= (exp + 1)
    return ans


def co_primes(x):
    """Return co-prime divisors of x."""
    for a in range(int(pow(x, 0.5)) + 1, 0, -1):
        if x % a == 0:
            b = x // a
        else:
            continue
        if math.gcd(a, b) == 1:
            return a, b


def main():
    num = int(input())
    array = [0] * (num + 1)

    def func(x):
        if x == 1:
            return 1
        elif x == 2:
            return 4
        a, b = co_primes(x)
        if min(a, b) == 1:
            # x is prime
            tmp = max(a, b)
            return tmp * count_divs(tmp)
        else:
            return array[a] * array[b]

    ans = 0
    for x in range(num):
        x += 1
        tmp = func(x)
        array[x] = tmp
        ans += tmp

    print(ans)


if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

sys.setrecursionlimit(10 ** 9)
n = int(input())


def make_prime_list(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]


prime_list = make_prime_list(math.floor(math.sqrt(10 ** 7 + 1)))


def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        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


# def solve(n, acc):
#   if (n == 1):
#     return acc
#   else:
#     return solve(n - 1, search_divisor_num_1(n) * n + acc)

ans = 1
while n > 1:
  ans += search_divisor_num_1(n) * n
  n = n - 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())


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

    b = 1
    for _, v in a.items():
        b *= v + 1
    return b


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

Submission status: Time Limit Exceeded

Solution code:
def f(n):
    y = 0
    i = 1
    while i * i <= n:
        if n % i == 0:
            if i * i == n:
                y += 1
            else:
                y += 2
        i += 1
    return y

n = int(input())

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

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 K in range(N+1):
    f_K = make_divisors(K)

    sum = sum + K * len(f_K)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

table = [0] * (N + 1)

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

print(sum(table))

Submission status: Time Limit Exceeded

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

class Prime():
    # コンストラクタ
    # エラストテネスの篩
    def __init__(self,num):
        self.num = num
        self.sieve = [0] * (self.num + 1)
        self.sieve[0] = -1
        self.sieve[1] = -1
        for i in range(2,self.num+1):
            if not self.sieve[i]:
                self.sieve[i] = i
                for j in range(i * i,self.num + 1,i):
                    if not self.sieve[j]:
                        self.sieve[j] = i

    # 素数判定
    def isPrime(self,num = None):
        if num is None:
            num = self.num
        if self.sieve[num] == num:
            return True
        else:
            return False
     
    # 素因数分解
    def PrimeFact(self,num = None):
        if num is None:
            num = self.num
        fact = {}
        while self.sieve[num] != num:
            if self.sieve[num] in fact.keys():
                fact[self.sieve[num]] += 1
            else:
                fact[self.sieve[num]] = 1
            num //= self.sieve[num]
        if self.sieve[num] in fact.keys():
            fact[self.sieve[num]] += 1
        else:
            fact[self.sieve[num]] = 1
        return fact

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    P = Prime(n)
    ans = 1
    for i in range(2,n+1):
        fact = P.PrimeFact(i)
        count = 1
        for x in fact.keys():
            count *= (fact[x] + 1)
        ans += i * count
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
data = [0 for _ in range(N)]
i = 1
heiho = set()
while i ** 2 <= N:
    heiho.add(i**2)
    i += 1
i -= 1
for j in range(1, i + 1):
    k = 1
    while j * k <= N:
        if j**2 <= j*k:
            data[j * k - 1] += 1
        k += 1
answer = 0
for s in range(len(data)):
    if s+1 in heiho:
        answer += (s + 1) * ((data[s]-1) * 2 + 1)
    else:
        answer += (s + 1) * data[s] * 2

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
def mini(g):
    divisors = []
    for i in range(1, int(g**0.5)+1):
        if g % i == 0:
            divisors.append(i)
            if i != g // i:
                divisors.append(N//i)
    return len(divisors)
ans=0
for i in range(1,N+1):
    f=mini(i)
    ans+=f*i
print(ans)

Submission status: Time Limit Exceeded

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

L = [0 for i in range(n)]
m = n//2
for i in range(1, m+1):
    t = i
    while t <= n:
        L[t-1] += 1
        t += i

for i in range(m, n):
    L[i] += 1
# print(L)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
allnum = np.array(range(1, N+1))

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

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

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

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

    return arr

number =list(num_divisors_table(N))
del number[0]
number = np.array(number)


number = np.array(number)
answer = number*allnum
print(sum(answer))

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)

    divisors.sort()
    return len(divisors)

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

Submission status: Time Limit Exceeded

Solution code:
#ABC172D
N = int(input())
ans = 0
for n in range(1,N+1):
    cot = 0
    i = 1
    while i*i <= n:
        if n / i == i:
            cot = cot + 1 
            break
        elif n % i == 0:
            cot = cot + 2
        i += 1
    ans= ans + cot*n
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [1]*(N+1)
cnt = 1
for i in range(2, N+1):
    for j in range(i, N+1, i):
        A[j] += 1
    cnt += i*A[i]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
N = int(input())
S = 0
def f(n):
  ctr = 0
  for j in range (1, n+1//2 + 1):
    if n%j == 0:
      ctr += 1
  return ctr
for i in range (1, N+1):
  ctr = f(i)
  S += i*ctr
print(S)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

sum = 0
for a in range(1,N+1):
    sum += a * make_divisors(a)
print(sum)

Submission status: Time Limit Exceeded

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

def factorization(n):
    primen, degree, primend = [], [], {}
    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
            primen.append(i)
            degree.append(cnt)
            primend[i] = cnt
    if temp!=1:
        primen.append(temp)
        degree.append(1)
        primend[temp] = 1
    if primen==[]:
        primen.append(n)
        degree.append(1)
        primend[n] = 1
    return degree

def main():
    N = int(input())
    ret = 0
    for i in range(1,N+1):
        x = factorization(i)
        cnt = 1
        for xx in x:
            cnt*=(xx+1)
        ret += i * cnt

    print(ret-1)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(10**6)

def Ed(num):
    ret=[]
    for i in range(1,int(num**0.5)+1):
        if num%i==0:
            ret.append(i)
            if num//i!=i:
                ret.append(num//i)
    #ret.sort()
    return len(ret)
def main():
    n=int(input().rstrip())
    ans=0
    for i in range(1,n+1):
        ans+=i*Ed(i)
    print(ans)

if __name__=="__main__":main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
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(stdin.readline().rstrip())
ans = 0
for i in range(n):
    i += 1
    ans += i*len(make_divisors(i))
print(ans)