Max Game
Practice
3.8 (4 votes)
Basic math
Basic programming
Basics of bit manipulation
Bit manipulation
Basics of bit manipulation
Problem
84% Success 1660 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an integer \(N\).

We represent the number \(N\) as the sum of distinct numbers that are powers of \(2\).

Task

If we put these numbers in an array, your task is to find the maximum element in this array.

Example

Assumption:

\(​N=10 ​\)

Approach:

\(10\) can be expressed as the sum of \([1,2,8]\) which are powers of \(2\) and the
maximum of these numbers is \(8\). Hence, the answer is \(8\).

Function description

Complete the function solve provided in the editor. This function takes the following one parameter and returns the required answer:

\(N\): the integer which is to be represented as the sum of powers of \(2\).

Input format

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).

The first line contains \(T\) denoting the number of test cases. \(T\) also specifies the number of times you have to run the solve function on a different set of inputs.
For each test case:
The first line contains the integer \(N\).

Output format
For each test case, print the answer in a new line. 

Constraints

\(1 \leq T \leq 10\)
\(1 \leq N \leq 10^{6}\)

Code snippets (also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
9 votes
Tags:
Bit ManipulationBasics of Bit ManipulationBasic Programming
Points:10
87 votes
Tags:
Basic ProgrammingBit ManipulationC++
Points:10
80 votes
Tags:
Bit manipulationBit ManipulationBasics of Bit ManipulationBasic Programming