Count Even and Odd Bits
Given a non-negative integer N, count the number of set bits (1s) that are at even positions and the number of set bits that are at odd positions. Bit positions are counted from right to left, starting at position 0. For example, in the binary representation of 13 (1101), the bit at position 0 is 1, position 1 is 0, position 2 is 1, and position 3 is 1. The set bits are at positions 0, 2, and 3. Positions 0 and 2 are even, and position 3 is odd. So, for N=13, the count of even-positioned set bits is 2, and the count of odd-positioned set bits is 1.
Input
A single line containing a non-negative integer N.
Output
Print two space-separated integers: the count of even-positioned set bits followed by the count of odd-positioned set bits.
Constraints
0 <= N <= 10^9
Example 1
13
2 1
Binary of 13 is 1101. Set bits at positions 0 (even), 2 (even), 3 (odd). Counts: even=2, odd=1.
Example 2
7
2 1
Binary of 7 is 111. Set bits at positions 0 (even), 1 (odd), 2 (even). Counts: even=2, odd=1.
Hints
Similar problems
- Count Numbers with Even Set BitsEasy
- Count Pairs with Same Most Significant BitEasy
- The Polite WaiterEasy
- Count Non-Alphabetic CharactersEasy
- Count Character OccurrencesEasy
- Count Set BitsEasy
More topics: Hash Map and Hashing problems, Bit Manipulation problems, Beginner Coding Problems problems
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
13
7