丸紅プログラミングコンテスト2024(AtCoder Regular Contest 183)
翻译中…
Problem Statement
翻译中…
You are given positive integers $A$, $B$, $X$, $Y$, and $N$. Here, the following is guaranteed:
翻译中…
$A<B$$\gcd(A,B)=1$$1 \leq N \leq A+B-1$
翻译中…
For an integer $n$, define $f(n)$ as follows:
翻译中…
- You start with an integer
$x=0$.$f(n)$is the minimum total cost to achieve$x=n$by repeatedly performing the following operations. - Replace the value of
$x$with$x+A$. The cost of this operation is$X$.- Replace the value of
$x$with$x-A$. The cost of this operation is$X$. - Replace the value of
$x$with$x+B$. The cost of this operation is$Y$. - Replace the value of
$x$with$x-B$. The cost of this operation is$Y$.
- Replace the value of
翻译中…
It can be proved from the constraints on $A$ and $B$ that $f(n)$ is defined for any integer $n$.
翻译中…
Find the value of $\sum_{1 \leq n \leq N} f(n)$, modulo $998244353$.
翻译中…
There are $T$ test cases for each input.
翻译中…
Constraints
翻译中…
$1 \leq T \leq 1000$$1 \leq A<B \leq 10^9$$\gcd(A,B)=1$$1 \leq X,Y \leq 10^9$$1 \leq N \leq A+B-1$- All input values are integers.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
T
case_1
case_2
\vdots
case_T
翻译中…
Each test case is given in the following format:
翻译中…
A B X Y N
翻译中…
Output
翻译中…
Print the answer for each test case.
翻译中…
样例
Input #1
4
1 2 1 1 2
3 5 2 4 6
79 85 72 95 4
80980429 110892168 22712439 520643153 66132787
Output #1
2
34
18111
785776602
In the first test case, $f(1)=1$ and $f(2)=1$.
In the second test case, $f(1)=8$, $f(2)=6$, $f(3)=2$, $f(4)=10$, $f(5)=4$, and $f(6)=4$.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。