#P10259. [COCI 2023/2024 #5] Piratski kod
[COCI 2023/2024 #5] Piratski kod
Background
Translated from COCI 2023/2024 Contest #5 Task 3「Piratski kod」
Problem Description
Captain Marrrtina and her pirate crew, after searching for three months, finally dug up a chest containing the lost treasure of the most famous Italian pirate. However, to open the chest, she needs a password, described in a message inside a bottle next to the chest.
The message says:
Only the most worthy pirates can open the chest. The password is the answer to the following riddle: For a binary sequence of length , where the only occurrence of two consecutive bits is at the end of the sequence, it is a pirate representation of a number if it satisfies:
$$s[0]\cdot \text{Fib}[2] + s[1]\cdot \text{Fib}[3] + s[2]\cdot \text{Fib}[4] + \ldots + s[a − 2]\cdot \text{Fib}[a] = \sum_{i=0}^{a-2} s[i]\cdot \text{Fib}[2 + i] = x$$Here is the -th Fibonacci number. Fibonacci numbers are defined as , , and for each , $\text{Fib}[y] = \text{Fib}[y − 1] + \text{Fib}[y − 2]$.
For example, , , , where denotes the pirate representation of a number.
A pirate code is a binary sequence (with no restriction about consecutive 's) that represents a sequence of positive integers. To read it, we split it into as many parts as possible, where each part is a pirate representation of some number (and there may be a suffix that is not a pirate representation of any number), and then we write down those integers in order. For example, we split into . The last part is not a pirate representation, so we discard it and obtain , which is read as the sequence .
The value of a pirate code equals the sum of the decoded positive integers. The value of the above password is .
My favorite number is the sum of the values of all pirate codes of length . Since this number can be very large, the password to open the chest is the remainder of when divided by .
— Leonarrrdo da Pisa
If Marrrtina cannot open the chest, her crew will consider her untrustworthy and force her to walk the plank.
Input Format
One line contains one integer .
Output Format
Output one line with integers. The -th integer should be the answer to the password riddle for length .
4
0 1 4 16
Hint
Sample Explanation 1
The codes of length are and , and both have value .
The code has value , and all other codes of length have value .
The code has value , and the code has value .
Subtasks
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 20 | |
| 2 | 40 | |
| 3 | 50 |
Translated by ChatGPT 5