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:
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; 
#--------------
ans=0
n = int(input())
for i in range(n+1):
    ans=ans+(i*divCount(i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
List=[1 for x in range(n+1)]
for x in range(2,n+1):
  for y in range(x,n+1,x):
    List[y]+=1
ans=0
for x in range(1,n+1):
  ans+=(List[x]*x)
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())
number=[0]*(N+1)
for i in range(N+1):
    number[i]=len(make_divisors(i))
ans=0
for j in range(N+1):
    ans+=j*number[j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def divs(M):
    divs = set()
    for i in range(1, int(M ** 0.5) + 1):
        if M % i == 0:
            divs.add(i)
            divs.add(M // i)
    return len(divs)

N = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def divCount(n):
	# sieve method for
	# prime calculation
	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
	
	# Traversing through
	# all prime numbers
	total=1
	for p in range(2,n+1):
		if (hh[p]==1):
			
			# calculate number of divisor
			# with formula total div =
			# (p1+1) * (p2+1) *.....* (pn+1)
			# where n = (a1^p1)*(a2^p2)....
			# *(an^pn) ai being prime divisor
			# for n and pi are their respective
			# power in factorization
			count=0
			if (n%p==0):
				while (n%p==0):
					n=int(n/p)
					count+=1
				total*=(count+1)
	
	return total

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
def make_divisors(n):
    num=0
    i = 1
    while i*i <= n:
        if n % i == 0:
            num+=1
            if i != n // i:
                num+=1
        i += 1
    return num

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:
n = int(input())
res = 0
import math

def divisorGenerator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(n / i)
    for divisor in reversed(large_divisors):
        yield divisor
for i in range(1,n+1):
    res += i * len(list(divisorGenerator(i)))
print(res)

Submission status: Time Limit Exceeded

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

# In[13]:


N = int(input())


# In[14]:


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[15]:


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


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
"""
NTC here
"""
 
 
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

profile = 0
pypy = 1
 
 
def iin(): return int(input())


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


def main():
    n = iin()
    a1 = [1]*(n+1)
    for i in range(2, n+1):
        if a1[i]==1:
            for j in range(i, n+1, i):
                a1[j] = i
    ans = 1
    dp = {}
    for i in range(2, n+1):
        x = i
        ch = {}
        while x>1:
            if x in dp:
                for j in dp[x]:
                    if j in ch:ch[j] += dp[x][j]
                    else: ch[j] = dp[x][j]
                break
            try:
                ch[a1[x]] += 1
            except:
                ch[a1[x]] = 1
            x //= a1[x]
        # print(i, ch)
        dp[i] = ch
        ch1 = 1
        for j in ch.values():
            ch1 *= (j+1)
        
        ans += ch1*i
    print(ans)
        










    




                

        

 
 
 
 
 
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
if pypy:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    if profile:
        import cProfile
        cProfile.run('main()')
    else:
        main()

Submission status: Time Limit Exceeded

Solution code:
def printDivisors(n) : 
	s=0
	i = 1
	while i <= n : 
		if (n % i==0) : 
			s+=1
		i = i + 1
	return s
s=0
for i in range(1,(int(input())+1)):
	s=s+(i*(printDivisors(i)))
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]

sum=0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ans=1
L=[1 for i in range(N+1)]
for i in range(2,N+1):
    ans+=i*(L[i]+1)
    for j in range(2,N+1):
        if j*i<=N:
            L[i*j]+=1
print(ans)
#print(L)

Submission status: Time Limit Exceeded

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

n=int(input())
s=0
for i in range(n):
    s+=(i+1)*make_divisors(i+1)
print(s)

Submission status: Time Limit Exceeded

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

N = int(input())
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 make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

def L(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())


def solver(N):

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

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

    solver(N)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def divisor_num(m):
    i = 1
    cnt = 0
    while i * i <= m:
        if m % i == 0:
            cnt += 2
            if i * i == m:
                cnt -= 1
        i += 1
    return cnt


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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

for i in range(1,n+1):

    for j in range(1,n+1):

        if j*i<=n:
            l[i*j]+=1
s=0
for j in range(1,n+1):
    s+=j*l[j]
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

Solution code:
def divisor(n):

    hh = [1] * (n + 1)

    p = 2
    while((p * p) < n):
        if (hh[p] == 1):
            for i in range((p * 2), n, p):
                hh[i] = 0
        p += 1
    total = 1
    for p in range(2, n + 1):
        if (hh[p] == 1):

            count = 0
            if (n % p == 0):
                while (n % p == 0):
                    n = int(n / p)
                    count += 1
                total *= (count + 1)

    return total

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

Submission status: Time Limit Exceeded

Solution code:
import math
def num_divisors_trial_division(n):
    num = 0
    for i in range(1, int(math.sqrt(n) + 1e-9) + 1):
        if n % i == 0:
            num += 1
            if n != i**2:
                num += 1
    
    return num
N=int(input())
ans=0
for i in range(1,N+1):
  ans+=num_divisors_trial_division(i)*i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ans = 0
for i in range(1, N+1):
    first = i
    n = N // i
    last = n * i
    ans += (first + last) * n // 2
print(ans)

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

res = 0

for i in range(1,N+1):
    tmp = len(div(i)[0:])
    res += i*tmp
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[::-1])
N=int(input())
ans=0
for i in range(1,N+1):
  ans+=make_divisors(i)*i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
def div(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 : # Otherwise count both 
                cnt = cnt + 2
                  
    return cnt 
    
xsum = 0
for i in range(1,int(input())+1):
    #print(div(i))
    xsum += div(i) * i
print(xsum)

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

def solve():
    N = int(sys.stdin.readline())
    ans = 0
    for n in range(1, N + 1):
        c = 0 
        for i in range(1, int(sqrt(n)) + 1):
            if n % i == 0:
                if n // i == i:
                    c += 1
                else:
                    c += 2
        ans += n * c
    print(ans)
    


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

Submission status: Time Limit Exceeded

Solution code:
def countDivisors(num):
    cnt = 0
    sqrt = int(num ** 0.5)
    for x in range(1, sqrt + 1):
        if num % x == 0:
            cnt += 1
    return cnt * 2 - (sqrt ** 2 == num)

N = int(input())

sum = 0
for n in range(1,N+1):
    l = countDivisors(n)
    sum += l*n
print(sum)

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

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

# Python3 program for finding 
# number of divisor 

# program for finding 
# no. of divisors 
def divCount(n): 

	# sieve method for 
	# prime calculation 
	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; 

	# Traversing through 
	# all prime numbers 
	total = 1; 
	for p in range(2, n + 1): 
		if (hh[p] == 1): 

			# calculate number of divisor 
			# with formula total div = 
			# (p1+1) * (p2+1) *.....* (pn+1) 
			# where n = (a1^p1)*(a2^p2).... 
			# *(an^pn) ai being prime divisor 
			# for n and pi are their respective 
			# power in factorization 
			count = 0; 
			if (n % p == 0): 
				while (n % p == 0): 
					n = int(n / p); 
					count += 1; 
				total *= (count + 1); 
				
	return total; 

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

Submission status: Accepted

Solution code:
from numba import njit, i8


@njit(i8(i8))
def solve(N):
    ans = 0
    for i in range(1, N + 1):
        j = N // i
        ans += j * (j + 1) // 2 * i
    return ans


N = int(input())
print(solve(N))

Submission status: Accepted

Solution code:
from numba import njit, i8


@njit(i8(i8))
def solve(N):
    ans = 0
    for i in range(1, N + 1):
        for j in range(i, N + 1, i):
            ans += j
    return ans


N = int(input())
print(solve(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
MAXN = 10**7+1
dp = [1] * (MAXN+1)
for i in range(2,MAXN+1):
    for j in range(i, MAXN+1,i):
        dp[j] += 1
n = I()
ans = 0
for i in range(1,n+1):
    ans += i * dp[i]
print(ans)

Submission status: Accepted

Solution code:

n = int(input())
ans = 0
x = n // 2
for i in range(1, n + 1):
    m = n // i
    ans += i * ((m + 1) * m) // 2
print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = [1]*(N+1)
for k in range(2,N+1):
    t = 1
    while k*t <= N:
        L[k*t] += 1
        t += 1
ans = 0
for k in range(1,N+1):
    ans += k*L[k]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
def f(x):
    return int(x * (x+1) / 2)

def main():
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        ans += i * f(N // i)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve():
    N = int(input())
    res = 0
    for i in range(1,N+1):
        k = N // i
        res +=i*(k+1)*k//2
    print(res)







if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N=int(input())

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

l=num_divisors_table(N)
ans=0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

#L=[n//i*(i+n//i*i)//2 for i in range(1,n+1)]
#print(sum(L))
ans=0
#for i in range(1,n+1):
#    for j in range(1,n+1):
#        if i%j==0:
#            ans+=i
#print(ans)
g=lambda x:(x*(n//x)*(n//x+1))//2
print(sum(g(i) for i in range(1,n+1)))

Submission status: Accepted

Solution code:
N = int(input())
cum = [1]*2 + [2]*(N-1)
for i in range(2,N//2+1):
    for j in range(2*i,N+1,i):
        cum[j] += 1
ans = 0
for i in range(1,N+1):
    ans += i*cum[i]
print(ans)

Submission status: Accepted

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

print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())
print(sum(N//n*(N//n+1)*n//2 for n in range(1,1+N)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for n in range(1, N+1):
    for m in range(n, N+1, n):
        ans += m

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
    n = int(string)
    return str(sum(i * (n // i) * (n // i + 1) // 2 for i in range(1, n + 1)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
s = 1
for a in range(1, int(n ** .5) + 1):
    div = n // a
    ans += ((div + 1) * div // 2 - s) * a * 2 + a * a
    s += a + 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
for a in range(1, n + 1):
    num = n // a
    ans += num * (num + 1) // 2 * a
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def calc(start, end):
	n = end // start
	return (n * (n+1) // 2) * start

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

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n = int(input())
    if n == 1:
        print(1)
        sys.exit()
    divs = np.arange(1, n + 1)
    divs2 = n // divs
    divs3 = divs2 * (divs2 + 1) // 2
    divs3 = divs3 * divs
    r = divs3.sum()
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
#import numpy as np
def main():
    n = int(input())
    if n == 1:
        print(1)
        sys.exit()
    r = 0
    for i1 in range(1, n + 1):
        num_of_div = n // i1
        r += num_of_div * (num_of_div + 1) // 2 * i1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline())
ans = 0
dp = [0]*(n+1)
for i in range(1,n+1):
    j = i
    while j <= n:
        dp[j] += 1
        j += i
for i in range(1,n+1):
    ans += dp[i]*i
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline())
ans = 0
for j in range(1,n+1):
    a = n//j
    ans += a*(a+1)*j//2
print(ans)

Submission status: Accepted

Solution code:
def g(n):
    ans = (n*(n+1))//2
    return ans

N = int(input())
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input());a=0
for i in range(1,N + 1):b=N//i;a+=(b*(b+1)*i//2)
print(a)

Submission status: Accepted

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

for i in range(1, N + 1):

    cnt = N // i
    ans += (cnt * (cnt + 1) * i // 2) 

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = 0
    for x in range(1, int(N ** 0.5) + 1):
        # x(1+2+3+...+e)
        e = N // x
        ans += x * (e * e + e - x * x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

ans = n * (n + 1) - 1
i = 2
while i * i <= n:
    m = n // i
    ans += i * (m * m - i * i + m)
    i += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = 0
    for x in range(1, N + 1):
        # x(1+2+3+...+e)
        e = N // x
        ans += x * e * (1 + e) // 2
    print(ans)


if __name__ == '__main__':
    main()