Given N and M Dexter wants to know how many pairs a,b(1 ≤ a < b ≤N) are there such that (a+b) is divisible by M.
For example when N=4 and M=3, there are 2 possible pairs the sum of which is divisible by M  and they are (1,2) and (2,4).

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

First line of input contains T(≤100000) which is the number of test cases. Each of the next T lines contains two integers N(1 ≤ N ≤ 10^{9}) and M(2 ≤ M ≤ 10^{9}).

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

Output one line per testcase, the number of pairs (a,b) as described before.

----- Sample Input 1 ------ 
3
2 3
4 3
1 6
----- Sample Output 1 ------ 
1
2
0

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Mathematics


Solutions:
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	c = n // m
	s = n % m
	if m == 2:
		print((s + c) * (c + s - 1) // 2 + c * (c - 1) // 2)
	elif m % 2 == 0:
		print(c * c * ((m - 1) // 2) + (c - 1) * c + c * s + max(0, s - m // 2))
	else:
		print(c * c * ((m - 1) // 2) + (c - 1) * c // 2 + c * s + max(0, s - m // 2))


t = int(input())
for x in range(t):
	(n, m) = map(int, input().split())
	total = n // m
	extra = n % m
	if m == 2:
		print((extra + total) * (total + extra - 1) // 2 + total * (total - 1) // 2)
	elif m % 2 == 0:
		print(total * total * ((m - 1) // 2) + (total - 1) * total + total * extra + max(0, extra - m // 2))
	else:
		print(total * total * ((m - 1) // 2) + (total - 1) * total // 2 + total * extra + max(0, extra - m // 2))


for _ in range(int(input())):
	line = input().strip().split()
	n = int(line[0])
	m = int(line[1])
	total = 0
	i = n // m
	j = n % m
	total += i * i * (m - 1)
	total += i * (i - 1)
	if m % 2 == 0:
		total -= i
	total = total // 2
	total += i * j
	if j > m // 2:
		total += j - m // 2
	print(total)


for _ in range(int(input())):
	(n, m) = [int(c) for c in input().split()]
	x = n // m
	y = n % m
	ans = 0
	ans += x * x * (m - 1)
	ans += x * (x - 1)
	if m % 2 == 0:
		ans -= x
	ans = ans // 2
	ans += x * y
	if y > m // 2:
		ans += y - m // 2
	print(ans)