Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 
Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: 
Let's define f(n) as the sum of all odd divisors of n. I.e. f(10) = 1 + 5 = 6 and f(21) = 1 + 3 + 7 + 21 = 32. The game is to calculate f(l) + f(l + 1) + ... + f(r - 1) + f(r) for the given integers l and r.
Have fun! But be careful, the integers might be quite big.

------ Input ------ 

The first line of the input contains one integer T denoting the number of test cases.
The only line of the test case description contains two positive integers l and r.

------ Output ------ 

For each test case, output the required sum on a separate line.

------ Constraints ------ 

$1 ≤ T ≤ 10$
$1 ≤ l ≤ r ≤ 10^{5}$

----- Sample Input 1 ------ 
2
1 10
42 42
----- Sample Output 1 ------ 
45
32
----- explanation 1 ------ 
In the first example case, f(1) + f(2) + ... + f(10) = 1 + 1 + 4 + 1 + 6 + 4 + 8 + 1 + 13 + 6 = 45
In the second example case, f(42) = 32.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Number theory

Mathematics

Range queries


Solutions:
T = int(input())
for i in range(T):
	f1 = 0
	f2 = 0
	(l, r) = list(map(int, input().split()))
	for j in range(1, r + 1, 2):
		f2 += j * (r // j)
	for j in range(1, l, 2):
		f1 += j * ((l - 1) // j)
	print(f2 - f1)


t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	sum1 = 0
	for i in range(1, r + 1, 2):
		sum1 += i * (r // i)
		sum2 = 0
	for i in range(1, l, 2):
		sum2 += i * ((l - 1) // i)
	print(sum1 - sum2)


def primeFactors(n):
	a = 1
	while n % 2 == 0:
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		j = 1
		s = 1
		while n % i == 0:
			n = n // i
			s += j * i
			j = j * i
		a *= s
	if n > 2:
		a = a * (1 + n)
	return a
A = [0] * 100001
for i in range(1, 100001):
	A[i] = primeFactors(i)
T = int(input())
for t in range(T):
	(l, r) = map(int, input().strip().split())
	print(sum(A[l:r + 1]))


from math import sqrt

def f(n):
	result = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i % 2 != 0:
				result += i
			if n // i % 2 != 0 and n // i != i:
				result += n // i
	return result
T = int(input())
for t in range(T):
	(l, r) = map(int, input().split())
	result = 0
	for i in range(l, r + 1):
		result += f(i)
	print(result)


for i in range(int(input())):
	(l, r) = list(map(int, input().split()))
	sum1 = 0
	sum2 = 0
	for i in range(1, r + 1, 2):
		sum1 = sum1 + i * (r // i)
	for i in range(1, l, 2):
		sum2 = sum2 + i * ((l - 1) // i)
	print(sum1 - sum2)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	c = sum((j * (b // j) for j in range(1, b + 1, 2)))
	d = sum((j * ((a - 1) // j) for j in range(1, a, 2)))
	print(c - d)


x = int(input())
divisors = [[] for _ in range(1000001)]
for i in range(1, 1000001, 2):
	for j in range(i, 1000001, i):
		divisors[j].append(i)
cache = {}
for c in range(x):
	(a, b) = map(int, input().split())
	if (a, b) in cache:
		print(cache[a, b])
		continue
	s = 0
	for d in range(a, b + 1):
		s += sum(divisors[d])
	cache[a, b] = s
	print(s)


t = int(input())
for j in range(t):
	(x, y) = map(int, input().split())
	sum = 0
	summ = 0
	for i in range(1, y + 1, 2):
		summ = summ + i * (y // i)
	for k in range(1, x, 2):
		sum = sum + k * ((x - 1) // k)
	print(summ - sum)


import math

def f(n):
	res = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i % 2 == 1:
				res += i
			if n // i % 2 == 1 and n // i != i:
				res += n // i
	return res
t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	res = 0
	for i in range(l, r + 1):
		res += f(i)
	print(res)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	sum1 = 0
	sum2 = 0
	for i in range(1, m + 1, 2):
		sum1 = sum1 + i * (m // i)
	for i in range(1, n, 2):
		sum2 = sum2 + i * ((n - 1) // i)
	print(sum1 - sum2)


def sieve_divisors(n):
	divisors = [0] * (n + 1)
	for i in range(1, n + 1):
		if i % 2 == 0:
			continue
		for j in range(i, n + 1, i):
			divisors[j] += i
	return divisors

def prefix_sum(divisors):
	prefix = [0] * len(divisors)
	for i in range(1, len(divisors)):
		prefix[i] = prefix[i - 1] + divisors[i]
	return prefix
t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	divisors = sieve_divisors(r)
	prefix = prefix_sum(divisors)
	result = prefix[r] - prefix[l - 1]
	print(result)


test_case = int(input())
for i in range(test_case):
	(l, r) = map(int, input().split())
	count = 0
	for j in range(1, r + 1, 2):
		m = l % j
		if m == 0:
			x = l
		else:
			x = l + (j - m)
		if x in range(l, r + 1):
			count += ((r - x) // j + 1) * j
	print(count)


t = int(input())
while t != 0:
	tp1 = 0
	tp2 = 0
	(l, r) = map(int, input().split())
	for j in range(1, r + 1, 2):
		tp2 += j * (r // j)
	for j in range(1, l, 2):
		tp1 += j * ((l - 1) // j)
	print(tp2 - tp1)
	t = t - 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	sum = 0
	a = a - 1
	for i in range(1, b + 1, 2):
		sum += (b // i - a // i) * i
	print(sum)


def factor(n):
	sum = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i % 2 != 0:
				sum += i
			if n // i != i and n // i % 2 != 0:
				sum += n // i
	return sum
factor_sums = [0] * (10 ** 5 + 1)
for i in range(1, len(factor_sums)):
	factor_sums[i] = factor_sums[i - 1] + factor(i)
t = int(input())
for i in range(t):
	(a, x) = map(int, input().split())
	print(factor_sums[x] - factor_sums[a - 1])


import math
for t in range(int(input())):
	(l, r) = map(int, input().split(' '))
	sum = 0
	for i in range(1, r + 1, 2):
		m = l % i
		if m == 0:
			x = l
		else:
			x = l + (i - m)
		if x in range(l, r + 1):
			sum += ((r - x) // i + 1) * i
	print(sum)