insidcode
ProblemsDuelLeaderboardStats
Sign In
  1. Home
  2. Problems
  3. Print all numbers from 1–n whose binary representation has an even number of 1s.

Print all numbers from 1–n whose binary representation has an even number of 1s.

Difficulty: Hard

Phase: 6 · Mixed Logical Challenges

XP Reward: 30 XP

Topics: Mixed Logical Challenges, Hard

Supported Languages: Python, JavaScript, C, C++, Java

Problem Description

Given N, print all numbers from 1 to N whose binary representation has an even number of set bits (1s), separated by space. Input Format: Read input from standard input (stdin). Output Format: Print the result to standard output (stdout).

Constraints

  • -10^9 <= N <= 10^9

Examples

Example 1

Input: 10

Output: 3 5 6 9 10

Explanation: Sample execution for input 10