デンソークリエイトプログラミングコンテスト2022(AtCoder Beginner Contest 239)
Ex
Dice Product 2
AtCoder
⌀ 2686
原题
←G →
翻译中…

Problem Statement

翻译中…

Snuke has a die (singular of dice) that shows integers from $1$ through $N$ with equal probability, and an integer $1$. He repeats the following operation while his integer is less than or equal to $M$.

翻译中…
  • He rolls the die. If the die shows an integer $x$, he multiplies his integer by $x$.
翻译中…

Find the expected value of the number of times he rolls the die until he stops, modulo $10^9+7$.

翻译中…

Definition of the expected value modulo $10^9+7$ We can prove that the desired expected value is always a rational number. Moreover, under the constraints of the problem, when the value is represented as an irreducible fraction $\frac{P}{Q}$, we can also prove that $Q \not\equiv 0 \pmod{10^9+7}$. Thus, an integer $R$ such that $R \times Q \equiv P \pmod{10^9+7}$ and $0 \leq R \lt 10^9+7$ is uniquely determined. Answer such $R$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 10^9$
  • $1 \leq M \leq 10^9$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N M

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
2 1
Output #1
2
The answer is the expected value of the number of rolls until it shows $2$ for the first time. Thus, $2$ should be printed.
Input #2
2 39
Output #2
12
The answer is the expected value of the number of rolls until it shows $2$ six times. Thus, $12$ should be printed.
Input #3
3 2
Output #3
250000004
The answer is $\frac{9}{4}$. We have $4 \times 250000004 \equiv 9 \pmod{10^9+7}$, so $250000004$ should be printed. Note that the answer should be printed modulo $\bf{10^9 + 7 = 1000000007}$.
Input #4
2392 39239
Output #4
984914531
Input #5
1000000000 1000000000
Output #5
776759630
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。