[link text][1]

Above is my solution to War of xor, can anyone tell me what is wrong in my solution ?

[1]: https://www.codechef.com/viewsolution/20215998

[link text][1]

Above is my solution to War of xor, can anyone tell me what is wrong in my solution ?

[1]: https://www.codechef.com/viewsolution/20215998

1 Like

Its integer overflow which is causing you WA. Convert int to long and submit.

Look, the multiplication of two integer numbers can give you an answer which is outside the range of **int**. For example 1000000 * 1000000 . both numbers are in the range of int but the multiplication is **10^12**.

which is outside the range of int.

Doing

**long a = 10^6 * 10^6;** is also wrong. Why? Because first the multiplication operation is performed than the assignment, hence the temporary answer should be stored somewhere but both the **operands** are int hence answer will we stored as **int** which is not enough, therefore it gives you wrong value. See this link for example

https://ideone.com/mJDPHQ

You can change **certain** variables to **long** data type or use **1L** while performing some operation(as I did in your code).

Hope it helps:)

Thank you soo much for your help.

1 Like