Блог пользователя mkmeden

Автор mkmeden, история, 22 месяца назад, По-английски

Can someone tell me whats wrong with my code

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

Code
  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
22 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
22 месяца назад, # |
  Проголосовать: нравится +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.