Sin mujer no hay llanto

Riaz_BSMRSTU Replay of BSMRSTU Home Qu...
Limits 1s, 512 MB

The nth element of FRUECAK Series can be calculated by following function:

int cal(int n, int d)
{
	if(n == 1) return 1;
	if(n % 2 == 1)
	{
		return cal(n - 1, d) + (n - 1) * d;
	}
	else
	{
		return cal(n - 1, d) - (n - 1) * d;
	}
}

You will be given n and d. You have to calculate sum of first n elements of this series.

Input

Input will contain T (1 ≤ T ≤ 105) Test cases.
Each test case will contain two numbers, n (1 ≤ n ≤ 2×109) and d (1 ≤ d ≤ 10).

Output

Print the sum of first n elements of this series.

Sample

InputOutput
3
1 2
2 2
3 2
1
0
3

Submit

Login to submit.

Statistics

76% Solution Ratio
Sajjat004Earliest, May '20
nnnnnnFastest, 0.0s
Tanim018Lightest, 1.2 MB
mdvirusShortest, 103B
Toph uses cookies. By continuing you agree to our Cookie Policy.