Immensely Long Expressions
Time limit1sMemory limit2048 MB
For each odd length n, find the expected value of a uniformly random valid arithmetic expression of that length, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
You own an artificial intelligence company that builds math-related chat bots. Usually things run smoothly, but today they do not. All of the AI-related machines have crashed, and to make matters worse, today is the day of the well-known annual International Competition on Preposterous Calculations (ICPC).
During the ICPC, participants often use your company's services to find the exact value of arithmetic expressions. This year is no different. The contest has already sent you a huge number of queries, but you cannot answer them right now.
Each query asks for the exact value of an arithmetic expression, a string of exactly characters. Here is odd, and the string satisfies the following conditions.
- The string consists only of the digits 0 to 9 and the arithmetic operation signs '
+', '-', '*', and '/'. - The characters at odd positions (1st, 3rd, ..., -th) are digits, and the rest are operation signs.
- A '
/' sign is never immediately followed by the digit 0.
For example, '1*2/3+4-5', '0', and '9/2' satisfy these conditions for some values of . '23-5', '-7', '5/0', and '998244353' do not.
The value of an expression follows the usual precedence rules. First, all multiplications and divisions are performed from left to right. Then all additions and subtractions are performed from left to right.
Assume that every expression satisfying the conditions above is equally likely to be the next query. What is the expected value of the result?
Input
The first line contains a single integer (), the number of test cases.
Each of the next lines contains a single odd integer (), the length of the expression.
Output
For each test case, print a single integer (). If the expected value is the irreducible fraction , then . The expected value is always a rational number for any , and such an always exists.
Note
The answers for the first three test cases are , , and , respectively.