You are not logged in. Please login at www.codechef.com to post your questions!

×

XORIER - Sep18 - Can anyone help me out?

link text

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

asked 17 Sep '18, 20:11

anwar_5256's gravatar image

3★anwar_5256
234
accept rate: 0%

edited 17 Sep '18, 20:14


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

link

answered 17 Sep '18, 20:40

pant0000's gravatar image

4★pant0000
1114
accept rate: 10%

Thank you soo much for your help.

link

answered 21 Sep '18, 22:52

anwar_5256's gravatar image

3★anwar_5256
234
accept rate: 0%

still i am getting wa

link text

link

answered 19 Sep '18, 11:37

anwar_5256's gravatar image

3★anwar_5256
234
accept rate: 0%

your code slightly updated gives AC
https://www.codechef.com/viewsolution/20237375

(19 Sep '18, 15:54) pant00004★

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:)

link

answered 19 Sep '18, 16:12

pant0000's gravatar image

4★pant0000
1114
accept rate: 10%

edited 19 Sep '18, 16:15

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,424
×304
×241

question asked: 17 Sep '18, 20:11

question was seen: 450 times

last updated: 21 Sep '18, 22:52