#P11220. 【MX-S4-T4】「yyOI R2」youyou 的三进制数
【MX-S4-T4】「yyOI R2」youyou 的三进制数
Background
Original link: https://oier.team/problems/S4D。
Problem Description
There are numbers from to .
Let denote the ternary representation of the decimal number . Unless explicitly stated otherwise, all numbers are in decimal form.
youyou wants to construct a non-negative integer sequence of length (), such that:
- 。
- There do not exist () such that 。
- For any , and satisfy at least one of the following four conditions:
- Remove the last digit of , and it becomes exactly (if there is only one digit, then after removing it the number becomes )。
- Append a digit to the end of , and it becomes exactly (if , then after appending, leading is discarded)。
- , the last digit of is not , and moving the last digit to the front makes it equal to 。
- When the length of is and the second highest digit of is non-zero, move the first digit of to the end; the decimal value of the resulting number is , and it is exactly equal to 。
Such a sequence is called "perfect".
youyou believes that a decimal triple is good if and only if it satisfies all of the following conditions:
- , and 。
- There exists at least one "perfect" sequence such that in decimal we have and , where is the length of the sequence。
- There exists at least one "perfect" sequence such that in decimal we have . At the same time, for any mentioned above, there is exactly one pair satisfying and such that 。
For each , find the number of ordered pairs that can form a good triple .
Input Format
One line containing a positive integer and a non-negative integer , whose meanings are given in the statement.
Output Format
Output lines. The -th line contains one number, indicating that when , the number of ordered pairs that can form a good triple .
4 3
20
20
20
20
20
Hint
[Sample Explanation #1]
There are numbers, whose ternary representations are respectively.
When , all pairs with satisfy the requirement.
Below is a proof that the triple is good.
When , the sequence can be .
Here, satisfy condition , satisfy condition , and satisfy condition .
It can be proved that only this sequence satisfies the requirement. Therefore, there exists such that . Hence is a good triple.
[Sample #2]
See ternary/ternary2.in and ternary/ternary2.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #3]
See ternary/ternary3.in and ternary/ternary3.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #4]
See ternary/ternary4.in and ternary/ternary4.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #5]
See ternary/ternary5.in and ternary/ternary5.ans in the attachment.
This sample satisfies the constraints of test points .
[Constraints]
This problem has test points, points each.
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| Yes | |||
| None | |||
Special property: 。
For all data, it is guaranteed that and 。
Translated by ChatGPT 5