Lonely Ones Binary ones (1) can get lonely if only zeros (0) surround them. Formally, we call such 1's "sparse". A number is defined as sparse if its binary representation has no two consecutive bits set. You are given an integer N and your task is to find out if it is sparse or not. Input The input contains an integer N. Output Print '1' if the number is sparse and '0' if the number is not sparse. Constraints 1 <= N <= 1018

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
Question
Lonely Ones
Binary ones (1) can get lonely if only zeros (0)
surround them. Formally, we call such 1's "sparse". A
number is defined as sparse if its binary
representation has no two consecutive bits set.
You are given an integer N and your task is to find
out if it is sparse or not.
Input
The input contains an integer N.
Output
Print '1' if the number is sparse and '0' if the number
is not sparse.
Constraints
1 <= N <= 1018
Example #1
Input
36
Output
1
Explanation: The binary representation of 36 is
100100. There are no consecutive ones present in
this. So it is a sparse number.
Example #2
Transcribed Image Text:Lonely Ones Binary ones (1) can get lonely if only zeros (0) surround them. Formally, we call such 1's "sparse". A number is defined as sparse if its binary representation has no two consecutive bits set. You are given an integer N and your task is to find out if it is sparse or not. Input The input contains an integer N. Output Print '1' if the number is sparse and '0' if the number is not sparse. Constraints 1 <= N <= 1018 Example #1 Input 36 Output 1 Explanation: The binary representation of 36 is 100100. There are no consecutive ones present in this. So it is a sparse number. Example #2
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Merge Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L