분모가 n 이하인 기약분수 중 주어진 구간에 들어가는 것의 개수를 998244353으로 나눈 나머지를 구한다.
어려움9정수론수학조합론구현아직 제출이 없습니다시간 제한10초메모리 제한512 MBRikka 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 continuous fractional expansion algorithm which can find the closest fraction ba to approximate a given number x among all the fractions with denominator less than n.
Rikka wants to estimate the difficulty of this problem. She picks a fraction ba which is less than x and picks a fraction dc which is greater than x. And she wants to find the number of rational numbers in the interval \[ba,dc] which can be represented by fractions with denominators less than or equal to n. Formally, given ba, dc, and n, Rikka wants to find the number of proper fractions fe (1≤e<f≤n, gcd(e,f)=1) which satisfy ba≤fe≤dc.
This task seems too hard for Rikka. Please help her find the answer.
The first line contains a single integer t (1≤t≤103), the number of test cases.
Each test case is given on a separate line containing five integers n, a, b, c, and d (0<ba<dc<1, 1≤a,b,c,d≤108).
It is guaranteed that both ba and dc are proper fractions, 1≤n≤1010, and there are at most 3 test cases with n>106.
For each test case, output a single line with a single integer: the answer modulo 998,244,353.