mkmeden's blog

By mkmeden, history, 2 years 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

| Write comment?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 years 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.