ITRIX_E - THE BLACK AND WHITE QUEENS
Subru and Shanmu are playing Chess. Shanmu wonder about queens . So he asked Subru the following question
“How many ways are there to place a black and a white Queen on an M * N chessboard such that they do not attack each other? The queen can be moved any number of unoccupied squares in a straight line vertically, horizontally, or diagonally..”
Subru gave the answer in seconds for a given chess board of size M x N (M<=N). Can you repeat the same with Your Code?
The first line contains the integer “t” which indicates the number of test cases. Each of the following t lines contains two integers M and N separated by spaces (M<=N).
Output for each case consists of one line: The number of ways of placing a black and a white queen on a M x N chess board such that they do not attack each other.
Constraints: T<=10000 , 2<=M <=10^10 (10 power 10 ) ,2<=N<=10^10 (10 power 10). And M<=N .
Warning, with some cases you'll have M > N, others with M <= N.
I suck at these problems, but like a lemming that doesn't die, just keeps falling off the cliff, I keep getting into them over and over again, thinking it'd be easy, then spending hours staring at my own analysis as if it was written in Etruscan. Then I go grab something from the fridge and out of the blue I get the idea that gets me to AC. So I never learn how to arrive at the solution in an orderly manner and next time I encounter "how many ways.." it's bound to cost me a whole evening. Again!
Is long long in C is enough?