This page is still under construction.

Parts of this page are still being built. What you see may change.

Nowhere Money

Time limit1sMemory limit128 MB

Summary
Represent each amount as a sum of T(s) values (T(n) = Fibonacci-like count) with the fewest slots whose sizes differ by at least 2, and print the sizes and values.
Level

Medium6 of 10

Topics
Greedy, Dynamic programming, Math, Implementation
Solved
No attempts yet

Problem

In the town of Nowhere, money is made of coins and slots. There are two kinds of coins: size-1 and size-2. A size-2 coin is exactly twice as thick as a size-1 coin. People stack coins inside a slot and use the filled slot as money.

Slots come in many sizes. A slot of size nn can hold a stack of coins whose total thickness equals that of nn size-1 coins. Only a completely filled slot counts as valid money.

The value of a filled slot is the number of distinct ways it can be filled with coins. For example:

  • A size-1 slot has only 11 way: a single size-1 coin.
  • A size-2 slot has 22 ways: two size-1 coins, or one size-2 coin.
  • A size-5 slot has 88 ways: 1 1 1 1 1, 1 1 1 2, 1 1 2 1, 1 2 1 1, 2 1 1 1, 1 2 2, 2 1 2, 2 2 1.

So a filled size-1, size-2, and size-5 slot is worth 11, 22, and 88 monetary units respectively (the value depends only on the slot size, not on which coins are used or how they are arranged). Write T(n)T(n) for the value of a filled slot of size nn.

Mr. Thinktwice runs a grocery store. He noticed that customers prefer shops that hand back change in a convenient form, and from a small survey he learned that customers want their change built from slots under two rules:

  1. The number of slots is as small as possible.
  2. Every two slot sizes differ by at least 22, so no two slots are the same size or adjacent sizes; this makes the slots easy to tell apart.

For a given amount of change, output a series of slot sizes that satisfies these rules, sorted in descending order. Every amount of change can be written as

X=∑i=1nT(si)=T(s1)+⋯+T(si)+⋯+T(sn),s1≫s2≫⋯≫sn>0X = \sum_{i=1}^{n} T(s_i) = T(s_1) + \cdots + T(s_i) + \cdots + T(s_n), \qquad s_1 \gg s_2 \gg \cdots \gg s_n > 0

where

  • XX is the amount of change,
  • nn is the number of slots,
  • sis_i is the size of the ii-th slot,
  • TT maps a slot size to its value (the number of distinct ways to fill it), and
  • j≫kj \gg k means j≥k+2j \ge k + 2.

For example:

10=T(5)+T(2)=8+210 = T(5) + T(2) = 8 + 2

1,000,000=T(29)+T(25)+T(23)+T(11)+T(9)=832040+121393+46368+144+551{,}000{,}000 = T(29) + T(25) + T(23) + T(11) + T(9) = 832040 + 121393 + 46368 + 144 + 55

Input

The input contains several amounts of change, one per line. Each amount is a positive integer not greater than 5×10185 \times 10^{18}. Input ends at end-of-file (EOF).

Output

For each amount of change, print four lines:

  1. the amount of change itself;
  2. the slot sizes in descending order, separated by single spaces (every slot size is at most 9090);
  3. the corresponding slot values, in the same order, separated by single spaces;
  4. a blank line.

Examples3

  1. Example 1

    Input
    1
    10
    1000000
    
    Expected output
    1
    1
    1
    
    10
    5 2
    8 2
    
    1000000
    29 25 23 11 9
    832040 121393 46368 144 55
    
  2. Example 2

    Input
    1
    2
    3
    4
    5
    6
    7
    8
    
    Expected output
    1
    1
    1
    
    2
    2
    2
    
    3
    3
    3
    
    4
    3 1
    3 1
    
    5
    4
    5
    
    6
    4 1
    5 1
    
    7
    4 2
    5 2
    
    8
    5
    8
    
  3. Example 3

    Input
    2
    3
    5
    8
    13
    21
    34
    55
    89
    
    Expected output
    2
    2
    2
    
    3
    3
    3
    
    5
    4
    5
    
    8
    5
    8
    
    13
    6
    13
    
    21
    7
    21
    
    34
    8
    34
    
    55
    9
    55
    
    89
    10
    89