A carnival technician wires a strand of gondola lights around a carousel using a single control code. The gondolas are numbered starting from 0, and the control code, written in binary, has its bit at position i (0-indexed from the least significant bit) telling whether gondola i's light is on (bit value 1) or off (bit value 0).
Given the control code as a positive integer, report two counts: how many switched-on gondolas sit at an even-numbered position, and how many sit at an odd-numbered position.
A single line containing one integer n, the control code.
Two space-separated integers: the count of switched-on gondolas at even positions, followed by the count at odd positions.
Example 1
Input
17
Expected
2 0
Explanation
17 in binary is 10001, with set bits at positions 0 and 4 (0-indexed from the least significant bit). Both positions are even, so the even count is 2 and the odd count is 0, giving output '2 0'.
Example 2
Input
2
Expected
0 1
Explanation
2 in binary is 10, with a single set bit at position 1. Position 1 is odd, so the even count is 0 and the odd count is 1, giving output '0 1'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →