Frieren wants to learn a new spell. Unfortunately, the spell is hidden in a grimoire that has an interesting lock on it. To help unlock the lock, help Frieren solve this problem!
The function $$$f(x, y)$$$ is defined below.
int f(int x, int y) {
int ans = 0;
while (x != 0 and y != 0) {
int g = gcd(x, y);
x -= g;
y -= g;
ans++;
}
return ans;
}
Calculate $$$$$$\sum_{i = 0}^{d} f(a + i, a + p^x + i)$$$$$$ where $$$p$$$ is a prime. Since the answer could be large print it modulo $$$10^9 + 7$$$.
The first line will contain four positive integers $$$a$$$, $$$p$$$, $$$x$$$, and $$$d$$$. Note that it is guaranteed that $$$p$$$ will be a prime.
$$$1 \le a \le a + p^x + d \le 10^{18}$$$.
Print a single integer representing the answer.
2 2 3 8
16
10 7 2 100
678
| Название |
|---|


