CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » July Cook Off  » The Black and White Knights

The Black and White Knights

Problem code: BWKNIGHT

  • All Submissions

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

Date: 2010-04-10
Time limit: 1s
Source limit: 50000
Languages: C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK JS


  • Submit

Comments

  • Login or Register to post a comment.

Is it possible for the answer

pragrame @ 24 Jul 2010 10:11 PM

Is it possible for the answer to overflow a 64 bit integer?

@ Pradeep : Please ask

syco_adm @ 24 Jul 2010 10:16 PM

@ Pradeep : Please ask questions pertaining to the clarity of the statement only.

If position of knights are

mcsharma1990 @ 24 Jul 2010 10:20 PM

If position of knights are interchanged then will it be considered a diffrent arrangements?

@Mahesh Chandra Sharma yes

syco_adm @ 24 Jul 2010 10:38 PM

@Mahesh Chandra Sharma yes

I'm tring to solve it on

mmirzayanov @ 24 Jul 2010 10:53 PM

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

DylanN @ 24 Jul 2010 11:09 PM

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

syco_adm @ 24 Jul 2010 11:16 PM

@Dylan : just to distinguish between the knights.

@Mike Mirzayanov: Try leaving

anup @ 24 Jul 2010 11:18 PM

@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?

ishandutta2007 @ 24 Jul 2010 11:21 PM

wats o/p for n=1 m=1?

0

syco_adm @ 24 Jul 2010 11:25 PM

0

damn!!!  i missed it.... i

raman bhatia @ 25 Jul 2010 12:10 AM

damn!!!  i missed it....

i thought its on25th :(

I can't cubmit a solution.

anton_postnikov @ 25 Jul 2010 12:10 AM

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

theeporithirumugam @ 25 Jul 2010 12:27 AM

 

Please Tell whether the answer will fit in 64 bit or we need bignums in the question itself

we need bignums

Fdg @ 25 Jul 2010 12:42 AM

we need bignums

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com