BitsGiven a number N, find the max number of consecutive set bits in the number.InputFirst line of input contains T - number of test cases. Its followed by T lines, each containing a single number N.
Question
BitsGiven a number N, find the max number of consecutive set bits in the number.InputFirst line of input contains T - number of test cases. Its followed by T lines, each containing a single number N.
Solution
No answer
Similar Questions
Look at the following sequence:3, 5, 6, 9, 10, 12, 17, 18, 20....All the numbers in the series have exactly 2 bits set in their binary representation. Your task is simple, you have to find the Nth number of this sequence.Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each containing a single number N.Output FormatFor each test case, print the Nth number of the sequence, separated by a newline. Since the number can be very large, print the number % 1000000007.Constraints30 points1 <= T, N <= 20070 points1 <= T, N <= 105100 points1 <= T <= 1051 <= N <= 1014ExampleInput512550100Output3510104016640
Given a number, swap the adjacent bits in the binary representation of the number, and print the new number formed after swapping.Input FormatThe first line of input contains T - the number of test cases. Each of the next T lines contains a number N.Output FormatFor each test case, print the new integer formed after swapping adjacent bits, separated by a new line.Constraints1 <= T <= 1000000 <= N <= 109ExampleInput410743100Output51123152
Max Score: 50You are given two numbers A and B. Write a program to count the number of bits to be flipped to change the number A to the number B. Flipping a bit of a number means changing a bit from 1 to 0 or vice versa.Input FormatThe first line of input contains T - the number of test cases. Each of the next T lines contains 2 integers A and B, separated by space.Output FormatFor each test case, print the number of bit flips required to convert A to B, separated by a new line.Constraints1 <= T <= 1000000 <= N <= 109ExampleInput420 1016 81 153549 24Output4236
Maximum count value of a n-bit counter is
Write the codeGiven a set of distinct positive integers, find the largest subset such that every pair of elements in the subset (i, j) satisfies either i % j = 0 or j % i = 0.For example, given the set [3, 5, 10, 20, 21], you should return [5, 10, 20]. Given [1, 3, 6, 24], return [1, 3, 6, 24]Sample Test CasesTest Case 1:Expected Output:Enter·the·elements·seperated·by·,·:1,2,3,4,8,10,16[1,·2,·4,·8,·16]Test Case 2:Expected Output:Enter·the·elements·seperated·by·,·:2,3[3]Test Case 3:Expected Output:Enter·the·elements·seperated·by·,·:3,5,10,20,21[5,·10,·20]
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.