Parity of Set Bits
EasyPractice library · +10 XPbit manipulationloopsbasic
Given a positive integer N, determine if the count of set bits (1s) in its binary representation is even or odd. Print 'EVEN' if the count is even, and 'ODD' if the count is odd.
Input
A single positive integer N.
Output
Print 'EVEN' or 'ODD'.
Constraints
1 <= N <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
13
Output
ODD
Binary of 13 is 1101. It has three set bits (1s). Three is odd, so the output is ODD.
Example 2
Input
10
Output
EVEN
Binary of 10 is 1010. It has two set bits (1s). Two is even, so the output is EVEN.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
13
Example 2 input
10