Lucky String Jackpot
Practice
4.4 (26 votes)
Ad Hoc
Algorithms
Basic programming
Medium
Open
Root
Problem
90% Success 2636 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Kuldeep's and Christie recently got her PhD in Maths. So to celebrate, they both decided to play games with mathematical sequences for their date nights.

The game they are playing today is "Jackpot Palindrome", the objective of the game is to find out length of the largest palindrome which only contains the digit "4" from a given string.

The reference string for today is the lucky string. Lucky string is the concatenation of all lucky numbers in ascending order. Lucky numbers are those numbers which contain only "4" and/or "5". For example 4, 5, 44, 54,55,444 are lucky numbers while 457, 987 ,154 are not. So the fist few digits of the lucky string are "4544455455444445454455..." .

Since the lucky string is infinite, Christie gives Kuldeep an integer N and Kuldeep only needs to consider the lucky string upto length N.

Everytime Kuldeep answers correctly, he gets a kiss from Christie, obviously he'd want to maximize the number of kisses he gets, so your task is to help Kuldeep answer correctly everytime.

Input:
First line contains no of test cases T.
Next T lines contains a single integer N.

Output:
A single integer which is length of the largest palindrome substring containing only digit "4" in lucky string of length N.

Constraints:
1<=T<=100000
1<=N<=10^15

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:30
49 votes
Tags:
MathMediumNumber theorySqrt-Decomposition
Points:30
36 votes
Tags:
AlgorithmsApprovedImplementationMathMediumOpen
Points:30
936 votes
Tags:
MathMedium