Weekly Challenge: Sum vs XOR

Given an integer, n, find each x such that:

0 ≤ x ≤ n
n + x = n ⊕ x
where ⊕ denotes the bitwise XOR operator. Then print an integer denoting the total number of x's satisfying the criteria above.

Input Format
A single integer, n.

Constraints

0 ≤ x ≤ 100

Output Format
Print the total number of integer x's satisfying both of the conditions specified above.

Sample Input 0

5

Sample Output 0

2

Explanation 0
For n = 5, the x values 0 and 2 satisfy the conditions:

5 + 0 = 5 ⊕ 0 = 5
5 + 2 = 5 ⊕ 2 = 7
Thus, we print 2 as our answer.

Sample Input 1

10

Sample Output 1

4

Explanation 1
For n = 10, the x values 0, 1, 4 and 2 satisfy the conditions:

10 + 0 = 10 ⊕ 0 = 10
10 + 1 = 10 ⊕ 10 = 11
10 + 4 = 10 ⊕ 4 = 14
10 + 15 = 10 ⊕ 5 = 15
Thus, we print 4 as our answer.

This challenge was created by Shafaet and posted on hackerrank.com.

Starts on Tue, 1 November 2016 10:00

Ends on Sun, 6 November 2016 10:00

Points you can get: 7