#P12299. [ICPC 2023 WF] A Recurring Problem
[ICPC 2023 WF] A Recurring Problem
题目描述
You have a very big problem! You love recurrence relations, perhaps a bit too much. In particular, you are a fan of positive linear recurrence relations (PLRR), which can be defined as follows. First, you choose the order of the relation. Then you choose coefficients , and the first elements of a sequence . The relation is called "positive" if all of these numbers are positive integers. The rest of the sequence can then be generated indefinitely using the formula
$$a_{i+k}=c_1\cdot a_i+c_2\cdot a_{i+1}+\ldots+c_k\cdot a_{i+k-1} \quad \text{for} \quad i\ge 1 $$The Fibonacci sequence is the most famous recurrence of this form, but there are many others.
In fact, yesterday, in a fit of mad mathematical inspiration, you wrote down all possible ways of choosing a positive linear recurrence relation, and each associated infinite sequence, on some index cards, one per card. (You have a lot of index cards; you buy in bulk.) It has all been a bit of a blur. But when you woke up today, you realized that you do not have a good way to order or count the PLRRs. You tried just sorting the sequences lexicographically, but there are too many that start with "" — you will never make it to the later ones.
Fortunately, inspiration struck again! You realized that you can instead order the PLRRs lexicographically by the generated part of the sequence only (that is, the part of the sequence starting after the initial values). Ties are broken by lexicographic order of the coefficients. For example comes before , even though the continuation of the sequence is the same for both. This allows you to properly index your cards, starting from , with every card being assigned a number.
Given the number on a card, describe the sequence on it!
输入格式
The input consists of a single line with an integer (), the index of the desired PLRR.
输出格式
Output four lines detailing the desired recurrence relation. The first line contains its order . The second line contains the coefficients . The third line contains the starting values . The fourth line contains the first of the generated values.
3
2
1 1
1 1
2 3 5 8 13 21 34 55 89 144
1235
4
1 1 3 1
3 2 1 1
9 15 44 99 255 611 1519 3706 9129 22377