Math String
Time limit2sMemory limit1024 MB
Sum the values of all length-N strings over digits 1-9 and the operators + and * that form valid expressions, modulo 998244353, with N up to 1e18.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math, Combinatorics, Matrix
- Solved
- No attempts yet
Problem
Consider a string of length made of 11 characters: '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '*'.
A string is called a math string if:
- The first and last characters of are neither '
+' nor '*'. - For any two consecutive characters of , at least one of them is neither '
+' nor '*'.
Every math string can be read as an arithmetic expression built from integers in decimal notation and the ordinary arithmetic operations, where multiplication takes precedence over addition. The value of each such expression can be computed: for example, the math string "35+2*6" has value . Find the sum of the values of all math strings of length , modulo .
Input
The input consists of one integer . ()
Output
Print one integer, the answer to the problem.
Notes
In sample 1 there are only 9 distinct one-digit math strings: the digits '1' through '9'. The sum of those digits, read as arithmetic expressions, is .