Rhombus Sum

0

0 votes
Mathematics
Problem

Vashist is a math enthusiast. One day, he decided to make a Rhombus of numbers. The numbers in the rhombus are filled as:

1) The center of the rhombus, i.e, where diagonals of the rhombus intersect has an integer N.

2) The numbers in its diagonals are filled by applying increasing Arithmetic Progression (A. P.) of size Z with a common difference D on left, right, top and bottom of the center of the rhombus.

3) Other numbers are filled as the sum of two adjacent numbers. Start filling other numbers from center.

See explanation of sample testcase for clarification.

Exapmle

In the above example, N=1, D=1 and Z=5.

He asks you to find the Rhombus Sum R which is equal to the sum of all the numbers in the rhombus formed if you are provided with the center of the rhombus N, the common difference D and the size Z of the progression.

Input:

  • First line will contain T , number of testcases. Then the testcases follow.
  • For each testcase, a single line containing three space-separated integers N,D,Z.

Output:

  • For every testcase, print in a single line containing the Rhombus Sum R.

Constraints

  • 1T105
  • 0N106
  • 0D106
  • 1Z30
Sample Input
4
1 1 4
1 1 5
3 4 4
3 4 3
Sample Output
109
273
391
131

Time Limit: 0.6
Memory Limit: 256
Source Limit:
Explanation

For case 1: N=1, D=1, Z=4, Rhombus is formed as:

 

Step 1
Step - 1
Step 2
Step - 2​​​
Step 3
Step - 3

 

Sum of all the numbers in the Rhombus =  109

 

Contributers:
Editor Image

?