A Recurring Problem

시간 제한20초메모리 제한1024 MB

요약
모든 양의 선형 점화식을 생성 부분의 사전순으로, 동률이면 계수의 사전순으로 정렬했을 때 n번째 점화식을 구한다.
난이도

어려움10점 중 8점

유형
조합론, 수학, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

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 kk of the relation. Then you choose coefficients c_1,c_2,…,c_kc\_1,c\_2, \dots ,c\_k, and the first kk elements of a sequence a_1,a_2,…,a_ka\_1,a\_2, \dots ,a\_k. 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⋅a_i+c_2⋅a_i+1+⋯+c_k⋅a_i+k−1a\_{i+k} = c\_1 \cdot a\_i + c\_2 \cdot a\_{i+1} + \cdots + c\_k \cdot a\_{i+k-1} for i≥1i≥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 “11” — 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 kk values). Ties are broken by lexicographic order of the coefficients. For example k=1k=1, c_1=2c\_1=2, a_1=2a\_1=2 comes before k=2,k=2, (c1,C2)=(2,1)(c1,C2)=(2,1), (a1,a2)=(1,2)(a1,a2)=(1,2), even though the continuation of the sequence is the same for both. This allows you to properly index your cards, starting from 11, 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 nn (1≤n≤1091≤n≤10^9), the index of the desired PLRR.

출력

Output four lines detailing the desired recurrence relation. The first line contains its order kk. The second line contains the kk coefficients c_1,…,c_kc\_1,\dots ,c\_k. The third line contains the kk starting values a_1,…,a_ka\_1,\dots ,a\_k. The fourth line contains the first 1010 of the generated values.

예제2

  1. 예제 1

    입력
    3
    
    예상 출력
    2
    1 1
    1 1
    2 3 5 8 13 21 34 55 89 144
    
  2. 예제 2

    입력
    1235
    
    예상 출력
    4
    1 1 3 1
    3 2 1 1
    9 15 44 99 255 611 1519 3706 9129 22377