mkmeden's blog

By mkmeden, history, 7 weeks ago, In English

Can someone tell me whats wrong with my code

https://www.hackerrank.com/challenges/xor-and-sum/problem

Code
 
 
 
 
  • Vote: I like it
  • +8
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by mkmeden (previous revision, new revision, compare).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Do you really convert $$$10^5$$$-bit number into unsigned long long value? unsigned long long type can contain only 64-bit numbers...

  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    ya but it fails the initial test case too..were a and b are less than 64-bit numbers

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

You cannot do b1 << 314159, integers can't hold that value

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

try to debug yourself bro.

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

For this questions you cannot use c++ standard int, long long int, or even unsigned long long int because integers in this question can go up to 10^5 bits long. So you must implement it yourself. Store a and b as strings, create an xor function for string representation of binary numbers, and use it on a, b. Next, notice that the summation is just the sum of a geometric sequence. The total sum is equal to ((a xor b)<<314160) — 1. After computing this value (in string representation because int cannot store this value) just compute the mod bit by bit. Sum them up and you have your answer.