The Black and White Knights
All submissions for this problem are available.
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? The knights have to be placed on different squares. A knight can move two squares horizontally and one square vertically, or two squares vertically and one square horizontally. The knights attack each other if one can reach the other in one move.
The first line contains the number of test cases T. Each of the next T lines contains two integers N and M.
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
|Tags||cook01, easy, syco|
|Time Limit:||0.164615 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.