AtCoder Beginner Contest 172 - Sum of Divisors

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-----
4

-----Sample Output-----
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.

Source: atcoder | Difficulty: MEDIUM_HARD


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


n = int(input())
print(sum((n // i * (i + n // i * i) // 2 for i in range(1, n + 1))))


N = int(input())
ans = 0
for j in range(1, N + 1):
	Y = N // j
	ans += Y * (Y + 1) * j // 2
print(ans)


N = int(input())
ans = 0
import math
for i in range(1, N + 1):
	max_i_multi = N // i
	ans += max_i_multi * (max_i_multi + 1) * i // 2
print(ans)


N = int(input())
out = 0
for X in range(1, N + 1):
	Y = N // X
	out += Y * (Y + 1) * X / 2
print(int(out))


N = int(input())
print(sum([N // i * (N // i + 1) * i // 2 for i in range(1, N + 1)]))


N = int(input())
t = 0
for i in range(1, N + 1):
	p = N // i
	t += i * p * (1 + p) / 2
print(int(t))


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


N = int(input())
sum = 0
for j in range(1, N + 1):
	sum += N // j * (N // j + 1) // 2 * j
print(sum)


n = int(input())
res = 0
for i in range(1, n + 1):
	ahaha = n // i
	res += (i + ahaha * i) * ahaha // 2
print(res)


n = int(input())
print(sum(((n - n % k) * (n // k + 1) // 2 for k in range(1, n + 1))))


N = int(input())
if N == 1:
	print(1)
	return

def divisor(n):
	m = N // n
	return n * m * (m + 1) // 2
M = N // 2
ans = 0
for i in range(2, M + 1):
	ans += divisor(i)
ans += N * (N + 1) - M * (M + 1) // 2
print(ans)


N = int(input())
print(sum([n * (N // n) * (N // n + 1) // 2 for n in range(1, N + 1)]))


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


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


n = int(input())
t = 0
k = 0
for i in range(1, n + 1):
	k = n // i
	t += i * k * (k + 1) // 2
print(t)


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


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

def __starting_point():
	import sys
	print(solve(sys.stdin.read().strip()))
__starting_point()


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


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


n = int(input())
s = 0
for i in range(1, n + 1):
	a = n // i
	z = a * (a + 1) * i // 2
	s += z
print(s)


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


N = int(input())
r = 0
for n in range(N):
	d = N // (n + 1)
	r += d * (d + 1) * (n + 1) // 2
print(r)


N = int(input())
S = 0
for i in range(1, N + 1):
	S = S + i * (N // i) * (N // i + 1) // 2
print(S)


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(MAP())
n = INT()
ans = 0
for x in range(1, n + 1):
	y = n // x
	ans += y * (y + 1) * x // 2
print(ans)


n = int(input())
print(sum(map(lambda x: n // x * (n // x + 1) // 2 * x, range(1, n + 1))))


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
	n = int(input())
	if n == 1:
		print(1)
		return
	r = 0
	for i1 in range(1, n + 1):
		y = n // i1
		r += y * (y + 1) // 2 * i1
	print(r)

def __starting_point():
	main()
__starting_point()


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


N = int(input())
ans = int(sum([j * (N // j) * (N // j + 1) / 2 for j in range(1, N + 1)]))
print(ans)


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


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


n = int(input())
f = [0] * (n + 1)
ans = 0
dic = {}
for i in range(1, n + 1):
	j = n // i
	dic[j] = dic.get(j, 0) + i
for (key, value) in dic.items():
	ans += value * key * (key + 1) // 2
print(ans)


n = int(input())
x = 0
for i in range(1, n + 1):
	for j in range(i, n + 1, i):
		x += j
print(x)


n = int(input())
g = 0
for i in range(n):
	g += n // (i + 1) * ((n // (i + 1) + 1) * (i + 1) / 2)
print(int(g))


def main(N):
	x = 0
	for a in range(1, N + 1):
		b = N // a
		x += a * b * (b + 1) // 2
	return x
N = int(input())
print(main(N))


def solve(n):
	su = 0
	for i in range(1, n + 1):
		m = n // i
		su += m * (2 * i + (m - 1) * i) // 2
	return su
n = int(input())
print(solve(n))


N = int(input())
m = 0
for i in range(1, N + 1):
	for j in range(1, N // i + 1):
		m += i * j
print(m)


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


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


def main():
	import sys
	pin = sys.stdin.readline
	pout = sys.stdout.write
	perr = sys.stderr.write
	N = int(pin())
	ans = 0
	for i in range(1, N + 1):
		ans += N // i * (N // i + 1) * i // 2
	print(ans)
	return
main()


n = int(input())
g = 0
for i in range(1, n + 1):
	g += 0.5 * i * (n // i) * (n // i + 1)
print(int(g))


N = int(input())
SUM = 0
for i in range(1, N + 1):
	SUM += i * (N // i) * (N // i + 1) // 2
print(SUM)


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


import numba

@numba.njit
def main(N):
	x = 0
	for a in range(1, N + 1):
		b = N // a
		x += a * b * (b + 1) // 2
	return x
N = int(input())
print(main(N))


n = int(input())
s = 0
for d in range(1, n + 1):
	for k in range(d, n + 1, d):
		s += k
print(s)


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

def __starting_point():
	main()
__starting_point()


n = int(input()) + 1
print(sum((j for i in range(1, n) for j in range(i, n, i))))


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


N = int(input())
ans = 0
for num in range(1, N + 1):
	count = N // num
	ans += count * (count + 1) // 2 * num
print(ans)


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


def main():
	n = int(input())
	ans = 0
	for k in range(1, n + 1):
		ans += k * (n // k) * (n // k + 1) // 2
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numba

def main():

	@numba.njit
	def solve(n):
		r = 0
		for i1 in range(1, n + 1):
			y = n // i1
			r += y * (y + 1) // 2 * i1
		return r
	no = int(input())
	print(solve(no))

def __starting_point():
	main()
__starting_point()


n = int(input())
ass = 0
for j in range(1, n + 1):
	ass += int(n / j) * (int(n / j) + 1) * j // 2
print(ass)


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


def main():
	n = int(input())
	ans = 0
	for i in range(1, n + 1):
		tmp = n // i
		ans += i * tmp * (tmp + 1) // 2
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


import sys
N = int(sys.stdin.readline())
ans = sum((N // x * (N // x + 1) * x // 2 for x in range(1, N + 1)))
print(ans)


import numpy as np
from numba import njit

@njit
def main(N):
	spf = np.zeros(N + 1, np.int32)
	prime = np.zeros(N + 1, np.int32)
	index = 0
	for i in range(2, N + 1):
		if not spf[i]:
			spf[i] = i
			prime[index] = i
			index += 1
		for j in range(index):
			if prime[j] > i or i * prime[j] > N:
				break
			spf[i * prime[j]] = prime[j]
	ans = 0
	for k in range(1, N + 1):
		n = k
		before = spf[n]
		count = 0
		fk = 1
		while n > 1:
			if spf[n] == before:
				count += 1
				n //= spf[n]
			else:
				fk *= count + 1
				before = spf[n]
				count = 1
				n //= spf[n]
		fk *= count + 1
		ans += k * fk
	print(ans)
N = int(input())
main(N)


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

def __starting_point():
	main()
__starting_point()


N = int(input())
s = 0
for i in range(1, N + 1):
	s += i * (N // i) * (N // i + 1) // 2
print(s)


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

def __starting_point():
	solve()
__starting_point()


def solve(N):
	answer = 0
	for i in range(1, N + 1):
		mprime = N // i
		answer += i * (mprime * (mprime + 1)) // 2
	return answer

def main():
	N = int(input())
	answer = solve(N)
	print(answer)

def __starting_point():
	main()
__starting_point()


N = int(input())
t = 0
for j in range(1, N + 1):
	m = N // j
	t += (1 + m) * m // 2 * j
print(t)


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)
		return
	divs = np.arange(1, n + 1)
	divs2 = n // divs
	divs3 = divs2 * (divs2 + 1) // 2
	divs3 = divs3 * divs
	r = divs3.sum()
	print(r)

def __starting_point():
	main()
__starting_point()


import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def S_MAP():
	return map(str, input().split())

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

def S_LIST():
	return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
ans = 0
for i in range(1, N + 1):
	n = N // i
	ans += i * n * (n + 1) // 2
print(ans)


import numba

@numba.njit
def main(N):
	x = 0
	for i in range(1, N + 1):
		for j in range(i, N + 1, i):
			x += j
	return x
N = int(input())
print(main(N))


import sys
N = int(sys.stdin.readline())
ans = 0
for x in range(1, N + 1):
	y = N // x
	ans += y * (y + 1) * x // 2
print(ans)


import sys

def solve(n):
	su = 0
	for i in range(1, n + 1):
		m = n // i
		su += m * (2 * i + (m - 1) * i) // 2
	return su
if sys.argv[-1] == 'ONLINE_JUDGE':
	from numba.pycc import CC
	cc = CC('my_module')
	cc.export('solve', '(i8)')(solve)
	cc.compile()
	return
n = int(input())
print(solve(n))


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


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


N = int(input())
ans = 0
for i in range(1, N + 1):
	num = N // i
	if num == 1:
		ans += i
	else:
		ans += num * (i + num * i) / 2
print(int(ans))


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

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

def X():
	return list(input())

def L():
	return list(input().split())

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

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
inf = float('inf')
N = k()
count = 0
for i in range(1, N + 1):
	t = N // i
	count += i * t * (t + 1) / 2
print(int(count))


import sys
input = sys.stdin.readline
n = int(input())
ans = 0
for i in range(1, n + 1):
	ans += i * (n // i) * (1 + n // i) // 2
print(ans)


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


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
n = int(input())
tmp = 0
res = 0
for i in range(1, n + 1):
	tmp = n // i
	res += tmp * (tmp + 1) * i // 2
print(res)


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


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


import sys

def input():
	return sys.stdin.readline().rstrip()

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

def __starting_point():
	main()
__starting_point()


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


import sys
import math
input = sys.stdin.readline

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

def __starting_point():
	main()
__starting_point()


n = int(input())
ans = 0
for j in range(1, n + 1):
	a = j
	d = n // j
	tmp = (a + a * d) * d // 2
	ans += tmp
print(ans)


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)


N = int(input())
P = 0
for i in range(1, N + 1):
	P += i * (N // i) * (N // i + 1) // 2
print(P)


n = int(input())
print(sum([n // m * (n // m + 1) * m // 2 for m in range(1, n + 1)]))


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)

def __starting_point():
	main()
__starting_point()


import math
import sys
import os
from operator import mul
import numpy as np
sys.setrecursionlimit(10 ** 7)

def _S():
	return sys.stdin.readline().rstrip()

def I():
	return int(_S())

def LS():
	return list(_S().split())

def LI():
	return list(map(int, LS()))
if os.getenv('LOCAL'):
	inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0] + '.txt'
	sys.stdin = open(inputFile, 'r')
INF = float('inf')
N = I()
ans = 0
for i in range(1, N + 1):
	y = N // i
	sum = y * (y + 1) * i / 2
	ans += sum
print(int(ans))

def seachPrimeNum(N):
	max = int(np.sqrt(N))
	seachList = [i for i in range(2, N + 1)]
	primeNum = []
	while seachList[0] <= max:
		primeNum.append(seachList[0])
		tmp = seachList[0]
		seachList = [i for i in seachList if i % tmp != 0]
	primeNum.extend(seachList)
	return primeNum

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


n = int(input())
print(sum((m * ((n // m) ** 2 + n // m - m ** 2) for m in range(1, int(n ** 0.5) + 1))))