You currently weigh WW units, but you would ideally weigh G<WG<W units. On some days you…
- User
You currently weigh WW units, but you would ideally weigh G<WG<W units. On some days you have the mental fortitude to eat well and exercise. On other days, not so much. Every day, with equal likelihood, your weight will either increase or decrease by 11 unit. While your regimen may be lax, you do have one strict rule: if your weight has ever been ww units, then you will never in the future allow it to exceed w+Lw+L. On any day where gaining 11 unit of weight would violate this constraint, you will guarantee that you lose 11 unit of weight instead. On average, how many days will it take you to reach a weight of GG units? The answer can be expressed as the ratio of two integers, p/qp/q in lowest terms. Output p×q−1p×q−1 (mod 998,244,353998,244,353). (a−1a−1 is the unique positive integer less than 998,244,353998,244,353 that satisfies a×a−1≡1a×a−1≡1 (mod 998,244,353998,244,353)). Constraints 1≤T≤901≤T≤90 1≤G<W≤10181≤G<W≤1018 0≤L≤10180≤L≤1018 Input Format Input begins with an integer TT, the number of test cases. Each case is a single line with the integers WW, GG, and LL. Output Format For the iith test case, print "Case #i: " followed by the expected number of days it will take you to reach a weight of GG units, expressed as described above. Sample Explanation In the first case, you weigh 201201 units and wish to reach a weight of 200200 units. You'll allow yourself to weigh 11 beyond your lowest weight, so on the first day you either lose 11 unit and stop, or you gain 11 unit, and then force yourself to lose 11 unit, returning back to 201201 units. So there's a 1/21/2 probability of finishing in 11 day, a 1/41/4 probability of 33 days, a 1/81/8 probability of 55 days, and so on. The sum of this series converges to 33 days on average. In the fourth case you aren't allowed to ever gain weight, so you'll reach your goal in 77,665,544,332,211−11,223,344,556,677=66,442,199,775,53477,665,544,332,211−11,223,344,556,677=66,442,199,775,534 days. 66,442,199,775,53466,442,199,775,534 % 99,8244,353=53,884,20799,8244,353=53,884,207, the final answer.
- Assistant
To solve this problem, we need to calculate the expected number of days it takes to reach a desired weight ( G ) starting from an initial weight ( W ), with certain constraints. Here's a step-by-step breakdown of the solution:
Understanding the Problem