Calculating Powers of Two
InterviewTime limit1sMemory limit512 MB
Given the final value Taeyoung got after subtracting 1 once during his powers-of-two computation, find which step K he made that mistake at.
- Level
Easy3 of 10
- Topics
- Math, Binary search, Implementation, Bit manipulation
- Solved
- No attempts yet
Problem
Taeyoung's hobby is computing powers of two.
Taeyoung knows that , and he will compute by hand, starting from and multiplying by 2 each time.
However, while multiplying by 2, Taeyoung made the mistake of subtracting 1 exactly once. (He makes the mistake only once, and after that he performs the multiplication by 2 correctly.)
For example, he computes correctly, then makes the absurd mistake of computing .
Then he goes on to compute , , and so on, so the error grows larger and larger.
Given , the value of that Taeyoung obtained, find the step where he made his first mistake.
Input
A positive integer is given.
is a value that can result when Taeyoung computes .
Output
Find the step where Taeyoung made his first mistake.
Print for the case where he computed .