CodSule - April edition RAGNAROK AND QUINJET

RAGNAROK AND QUINJET
Thor made an escape plan from Sakaar Planet with Bruce Banner. He told Bruce that they will find the Quinjet and fly their way along to Asgard easily. But Banner told Thor that in order to fly Quinjet Thor has to solve a puzzle. Given a number A, Thor is supposed to find the count of numbers that are when added to A or Xored(Bitwise Xor) with A gives the same value. Thor is supposed to print the total count of such numbers.

Input Format:
A single integer, A

Constraints:
0 ≤ A ≤ 10^15

Output Format:
Print the total number of integers satisfying the criteria.

Sample Input:
5
Sample Output:
2
Explanation:
5+0 = 5 and 5^0=5
5+2 = 7 and 5^2=7
So there are two such numbers which either added with A or Xored with A gives the same value.

A+n=A^n only when A&n=0
So,
if A’s bit is 0 then n can be 0 or 1
if A’s bit is 1 then n should be only 0
So,
Answer= 2 ^ (no of 0 bits in A)
Hit like if u get it :slight_smile:

1 Like