7
How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other?
A knight can move two squares horizontally and one square vertically, or two squares vertically and one square horizontally.
The knights have to be placed on different squares and the knights attack each other if one can reach the other in one move.
Input:
The first line contains the number of test cases T. Each of the next T lines contains two integers N and M, representing the dimensions of the board.
Output:
Output T lines, one for each test case, each containing the required answer for the corresponding test case.
Sample input:
3
2 2
2 3
4 5
Sample output:
12
26
312
Constraints
1 <= T <= 10000
1 <= N,M <= 100000
time limit 1 sec
Source Limit:
50000 Bytes
Winning criteria
Shortest code which runs with specified time limit decides the winner
i ll leave two days time for more users to try from today
I tidied up the formatting a little on your question, I hope you don't mind. Feel free to roll back the edit if you don't like it. – Griffin – 2012-08-27T11:09:47.027
@Griffin i am new here thanks for the edit ,please correct me if i make mistakes in future – BlueBerry - Vignesh4303 – 2012-08-27T12:13:06.210
You're going to want to put a winning criteria on your question before it gets down-voted by all the boring people on this site. You need to have a fairly objective way of choosing a winner. e.g. shortest code, fastest running code for a given input or some point system of your choosing. – Griffin – 2012-08-27T12:40:28.627
2Do we need to worry about board dimensions <= 0? – Matt – 2012-08-27T12:41:55.613
@Griffin does my winning criteria ok? – BlueBerry - Vignesh4303 – 2012-08-27T12:45:24.020
@vignesh I don't understand your answer. I was asking if a board dimension of 0 is valid inputs, and also if negative board dimensions are valid. – Matt – 2012-08-27T12:48:27.287
@Matt, the challenge is based on a very real-world game. You cannot place a knight on a board with negative or zero dimension. – Griffin – 2012-08-27T12:50:45.177
@matt consider my first input sample and you can clarify it – BlueBerry - Vignesh4303 – 2012-08-27T12:53:08.033
@vignesh actually nevermind, you had included that information in the original spec and I just missed it. – Matt – 2012-08-27T12:54:03.753
1
Question appears to be copied from here without any attribution.
– Paul R – 2012-09-01T14:41:32.157