问题 J: Roulette

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:21 通过:18

题目描述

Walk Alone is playing roulette, a kind of gambling. For simplification, we assume its rules and steps as follows:
  • The whole gambling process composes of many turns.
  • In the i-th turn:
  • Walk Alone can choose an integer xi and pay xi yuan as the wager.
  • If Walk Alone wins, he will get 2xi yuan from the maker, which means he gains xi yuan in this turn. Otherwise, the maker will devour the xi yuan he has paid, which means he loses xi yuan in this turn. The probability that Walk Alone wins is 0.5.
Walk Alone has n yuan initially, and he wants to earn an extra m yuan. He will use the following strategy to gamble:
  • In the first turn, Walk Alone pays 1 yuan as the wager, i.e., x1=1.
  • If Walk Alone wins in the (i−1)-th turn, then xi=1. Otherwise, xi=2x(i−1).
  • At the beginning of each turn, if Walk Alone has at least (n+m) yuan, then he gets satisfied and quits the game. Otherwise, he must pay xi yuan as the wager, and he will have to stop gambling if he has less than xi yuan.
 Walk Alone's good friend, Kelin wants to exhort him not to gamble. Tell him the probability that he successfully earns an extra m yuan.

输入格式

The only line of the input contains two integers n (1≤n≤10^9) and m (1≤m≤10^9), indicating the initial amount of money and the amount of money Walk Alone wants to earn.

输出格式

Output the probability that Walk Alone successfully earns an extra mmm yuan modulo 998244353. It can be shown that the answer can always be expressed as an irreducible fraction x/y, where x and y are integers and y≢0(mod998244353). Output such an integer a that 0≤a<9982443530 and a⋅y≡x(mod998244353).

输入样例 复制

2 2

输出样例 复制

623902721

数据范围与提示

In the first example, Walk Alone has 2 yuan initially.
In the first turn, he pays 1 yuan as the wager, and he has 1 yuan left. He must win the turn, or in the next turn he will have to pay 2 yuan, and he does not have enough money. The probability that he wins is 0.5.
In the second turn, he pays 1 yuan and has 2 yuan left. If he wins the turn, he will have 4 yuan, which reaches his goal. Otherwise, he will have to pay 2 yuan in the third turn, and he must win the turn to reach his goal. Hence the total probability is 0.5⋅(0.5+0.5⋅0.5)=3/8.

分类标签