当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6255:Rikka with Proper Fractions

题目描述
Rikka is a lovely girl. Although she was not good at math before, she has made great progress with the help of her boyfriend Yuta. And Rikka has been able to do math research by herself now.

Today, Rikka is reading some materials about rational number approximation. Rikka is interested in the algorithm continuous fractional expansion which can find a closest fraction $\frac{a}{b}$ to approximate a given number $x$ among all the fractions with the denominator less than $n$.

Rikka wants to estimate the difficulty of this problem. She picks up a fraction $\frac{a}{b}$ which is less than $x$ and picks up a fraction $\frac{c}{d}$ which is larger than $x$. And she wants to find the number of rational numbers in the interval $[\frac{a}{b},\frac{c}{d}]$ which can be represented by fraction numbers with the denominator less than $n$. Formally, given $\frac{a}{b},\frac{c}{d},n$, Rikka wants to find out the number of proper fractions $\frac{e}{f}(1 \leq e < f \leq n, \text{gcd}(e,f)=1)$ which satisfy $\frac{a}{b} \leq \frac{e}{f} \leq \frac{c}{d}$.

This task seems too hard for Rikka. So, could you please help her to find out the answer?
输入解释
The first line contains a single integer $t(1 \leq t \leq 10^3)$, the number of the testcases.

For each testcase, the first line contains five numbers $n,a,b,c,d(0 < \frac{a}{b} < \frac{c}{d} < 1, 1 \leq a,b,c,d \leq 10^8)$.

The input guarantees that both $\frac{a}{b}$ and $\frac{c}{d}$ are proper fraction numbers, $1 \leq n \leq 10^{10}$ and there are at most $3$ testcases with $n > 10^6$.
输出解释
For each testcase, output a single line with a single integer, the answer modulo $998244353$.
输入样例
3
5 1 2 3 4
10 1 2 7 9 
1000000 2 13 10000 10001
输出样例
4
10
620740490
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6255

最后修改于 2020-10-25T23:29:44+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 512000/512000K(Java/Others)