The Black and White KnightsProblem code: BWKNIGHT |
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.
Input :
The first line contains the number of test cases T. Each of the next T lines contains two integers N and M.
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
| Author: | syco |
| Date Added: | 10-04-2010 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments

Fetching successful submissions

Is it possible for the answer
Is it possible for the answer to overflow a 64 bit integer?
@ Pradeep : Please ask
@ Pradeep : Please ask questions pertaining to the clarity of the statement only.
If position of knights are
If position of knights are interchanged then will it be considered a diffrent arrangements?
@Mahesh Chandra Sharma yes
@Mahesh Chandra Sharma yes
I'm tring to solve it on
I'm tring to solve it on Java, but always get Runtime Error. Main class is "public class Main". It reads from standard input writes to standard output. What is the trick?
Do black knight and white
Do black knight and white knight refer to a knight on a black square and a knight on a white square, or is it just to distinguish between the knights?
@Dylan : just to distinguish
@Dylan : just to distinguish between the knights.
@Mike Mirzayanov: Try leaving
@Mike Mirzayanov: Try leaving the input stream open. It will be implicitly closed by the jvm. However, any buffered output stream should be closed/flushed explicitly.
wats o/p for n=1 m=1?
wats o/p for n=1 m=1?
0
0
damn!!! i missed it.... i
damn!!! i missed it....
i thought its on25th :(
I can't cubmit a solution.
I can't cubmit a solution. Submit button has the following URL: http://www.codechef.com/COOK01/problems/BWKNIGHT/#.
What is the trouble in?
Please Tell whether the
Please Tell whether the answer will fit in 64 bit or we need bignums in the question itself
we need bignums
we need bignums