PDP-24 (2012) - Camp junior - 1 (fib6)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

FIB6

The Fibonacci sequence is defined by the following recursive formula:

\displaystyle  F_0 = 0, F_1 = 1, F_{n+2} = F_{n+1} + F_n

The first terms of the sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597 and so on.

You are given a positive integer X. You need to determine if X can be expressed as the sum of at most six Fibonacci numbers, not necessarily distinct. If there are multiple ways to achieve this, you should find a solution with the smallest possible number of addends.

Input

The input consists of a single line containing a single integer X.

Output

The output should consist of a single line containing:

  • Either the word "impossible", without the quotes, if X cannot be written as the sum of at most six Fibonacci numbers,
  • Or an integer N between 1 and 6, inclusive, followed by N Fibonacci numbers separated by a single space, such that their sum is equal to X and N is minimized. If there are multiple correct solutions with the minimum number of addends, you can output any of them. All numbers in the line should be separated in pairs by a single space.
Constraints

1 \le X \le 1.000.000.000.
Execution time limit: 1 sec.
Memory limit: 16 MB.

Examples of Input - Output
1st

STDIN (fib6.in)

42

STDOUT (fib6.out)

2 8 34
2nd

STDIN (fib6.in)

166418946

STDOUT (fib6.out)

3 6765 832040 165580141
3d

STDIN (fib6.in)

649814661

STDOUT (fib6.out)

impossible

Comments

There are no comments at the moment.