Fibonacci Base
Time limit1sMemory limit128 MB
Given N up to 10^15, count how many '1' characters appear among the first N characters of the string formed by concatenating Zeckendorf (Fibonacci base) representations of 1,2,3,... in order.
- Level
Hard9 of 10
- Topics
- Math, Number theory, Binary search, Combinatorics
- Solved
- No attempts yet
Problem
The Fibonacci base is a way to represent every natural number uniquely using only the digits 0 and 1.
When a natural number is written in Fibonacci base as , its value is . Here is the Fibonacci sequence defined by and . To make every representation unique, no two 1s may be adjacent in the Fibonacci base.
The following shows several natural numbers written in Fibonacci base.
Now write the natural numbers in Fibonacci base one after another, and concatenate all of the resulting strings. The beginning of the string built this way is 110100101100010011010.
Find how many 1s appear among the first characters of this string.
Input
The first line contains an integer . ()
Output
Print the number of 1s among the first characters of the concatenated string.