Search code examples
c++algorithmc++11chess

Maximum number of Bishops that can be placed on a NxN Chessboard - SPOJ


Using the Constant time formula for Maximum bishops on a chessboard, which is:

int maxBishops(N) return 2*(N-1);

Implemented for the value of N lesser than 10^100, as follows: https://ideone.com/lvuiXW

Verified using Wolfram|Alpha but getting wrong answer on SPOJ's BISHOPS submission.

Am I missing something in the algorithm or is it an implementation issue?


Solution

  • A long sequence of all '0' will make your program fail.

    Maybe you should also check for inputs not being a number.

    EDIT: The input case 500000000000001 seems to fail also. I guess it will just print the carry.