9029: Double it or Give it to the Next Person

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Alice and Bob are playing a strange game usingcoins
Initially, Alice has x coins, and Bob has y coinsThey take turns choosing one of the followingoptions, starting with Alice:
1. Try to double it. With probability p (p <his/her coin gets doubled up, and with theremaining probability, he/she loses all the coinsand the game immediately.2. Pass to the next person. This literally meansdoing nothing in his/her turn. This operationcosts d coins and is only possible when he/shehas more than d coins
A player loses the game if he/she loses all his coinsDetermine the probability that Alice wins if bothplayers act optimally.

输入格式

The first line contains an integer 1(T<104),denoting the number oftestcases
For each test case, the only linecontains four integers x,y,d,c (1x,y < 109,1 <d < 100,1 < c < 49)suchthat the parameter of the game is set as p=c/100

输出格式

For each test case, output an integerin a line, denoting the probabilitythat Alice wins if both players actoptimally. Under the inputconstraints of this problem, it canbe shown that the answer can be written as P/Q  where P and Q are coprime integers and Q同余0(mod 998244353). You need to outputP.Q-1 mod 998244353 as an  answer ,where Q-1 is the modular inverse of Q with respect to 998244353

输入样例 复制

1
100 100 10 20

输出样例 复制

166374059