The Robbery

1.7

6 votes
Dynamic Programming
Problem

The Professor  got to know that there is much gold kept under the bank of spain secretly. Now professor making a master plan to rob all the gold there in bank of spain.Inorder to make a plan first he need to know how much gold is there inside the bank. Gold is kept in a floor and it looks like a grid of size N which consists of NN rooms containing gold. For each room the room number is equal to sum of its row number and column column number.

The total gold present in each room is equal to the absolute difference between the sum of even digits and odd digits in its room numbers(Units of gold) . For example if the room number is 3216 , then the total units of gold present in that room will be |(2+6)(3+1)|=4 units.

You are given the number N. You have to print the total units of gold present in bank of spain.

Input :

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The only line of each test case contains a single integer N.

Output :

For each test case, print the answer on a separate line.

Constraints :

1<=T<=105

1<=N<=106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Example case 3: There are 9 rooms. Room (1,1) has number 2, room (1,2) has number 3, etc. For each room, the units of gold in it is equal to the  absolute difference between sum of odd numbers and even numbers in that room number, so the total units of gold present is (2+3+4+3+4+5+4+5+6) = 36.

Editor Image

?