Write N as a sum of non-consecutive Fibonacci numbers F(1)=1, F(2)=2, maximizing the number of terms, or report -1.
Medium7GreedyMathNumber theoryImplementationNo attempts yetTime limit1sMemory limit128 MB*This problem has nothing to do with any real person.*
Long ago there lived a man named Sanya. Sanya had a friend named Roebeot. The two looked very much alike, but Roebeot was said to be a little smarter and Sanya a little better looking. Roebeot was stuck at 500 points in a game called Ovorwatch, which put him in the top 100.00%. Sanya liked to tease him about it. Roebeot got angry and offered a bet: if he ever climbed out of 500 points in Ovorwatch, Sanya would have to solve the problems Roebeot sets for the rest of his life. Sanya took the bet, sure that it would never happen.
And then it happened.
Roebeot pushed his score all the way into the 600s, and the bet left Sanya solving Roebeot's problems forever. Here is the problem Roebeot set. Take the natural number he gives you and write it as a sum of non-consecutive Fibonacci numbers. The Fibonacci sequence here is defined by F(1)=1, F(2)=2, F(n+2)=F(n+1)+F(n). Non-consecutive means the indices of the chosen terms are never neighbours. Foolish Sanya works the Fibonacci sequence out by hand, it takes forever, and he is going out of his mind. Clever Roebeot teased him for not even managing that much, and Sanya sulked. Write a program that takes the work off sulking Sanya's hands.
The first line contains a natural number N. (1≤N<1018)
If N can be written as F(i1)+F(i2)+⋯+F(ik) with i1<i2<⋯<ik and no two neighbouring indices consecutive, that is ij+1−ij≥2 for every j, print k on the first line and print F(i1),F(i2),…,F(ik) separated by spaces on the second line. Otherwise print −1 on the first line. If several such representations exist, print the one with the most terms.