### mkmeden's blog

By mkmeden, history, 6 weeks ago,

Can someone tell me whats wrong with my code

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

Code

• +8

 » 6 weeks ago, # |   0 Auto comment: topic has been updated by mkmeden (previous revision, new revision, compare).
 » 6 weeks ago, # |   0 Do you really convert $10^5$-bit number into unsigned long long value? unsigned long long type can contain only 64-bit numbers...
•  » » 6 weeks ago, # ^ |   0 ya but it fails the initial test case too..were a and b are less than 64-bit numbers
 » 6 weeks ago, # |   0 You cannot do b1 << 314159, integers can't hold that value
•  » » 6 weeks ago, # ^ |   0 then how to solve this problem??
 » 6 weeks ago, # |   0 try to debug yourself bro.
 » 6 weeks ago, # |   +3 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.