Rod Cutting Problem
Practice
3.4 (803 votes)
Bit manipulation
Hiring
Approved
Easy
Problem
22% Success 11621 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

A young mischievous boy Harsh, got into a trouble when his mechanical workshop teacher told him to cut Iron rods. The rod cutting algorithm is as follows:

Step 1. If the rod can be divided into two equal parts, cut it and choose any one of them.

Step 2. Else cut the rod into two parts having non-zero integral lengths such that the difference between the lengths of the two pieces is minimized, and then choose the piece having smaller length.

Step 3. Repeat the above algorithm with the currently chosen piece. If the length of the currently chosen piece becomes 1 , stop the algorithm.

There can be special rods which require Step 2 in every step of its cutting. Harsh want to find out the number of such special rods. Help Harsh to find out the answer.

Input:
The first line of the input will contain T, the number of test-cases.
Each subsequent T lines will contain an integer N, where N is the range of lengths of rods from 1 to N .

Output:
For each test-case print the required answer.

Constraints:

  • \(1 \le T \le 1000\)
  • \(1 \le N \le 10^9\)

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:20
16 votes
Tags:
EasyImplementationadhoc
Points:30
1 votes
Tags:
OpenDisjoint-set data structureMediumStringBasics of Disjoint Data StructuresDisjoint setsData StructuresDisjoint Data StructuresOpen
Points:20
20 votes
Tags:
Binary search algorithmNumber TheoryAlgorithmsEasyMathematicsOpenApproved
Editorial

Login to unlock the editorial