Rational Dimasik
Time limit2sMemory limit512 MB
Given n fractions, compute the product, over all pairs, of the denominator of their difference written in lowest terms, modulo 998244353.
- Level
Hard9 of 10
- Topics
- Number theory, Math, Combinatorics, Sorting
- Solved
- No attempts yet
Problem
Little Dimasik is a fan of rational numbers. He has rational numbers . Recently Dimasik learned how to subtract rational numbers.
Every rational number can be written uniquely as an irreducible fraction , where and are coprime integers and .
Define the function as the denominator of the rational number in irreducible form. For example, .
Now Dimasik wants to compute But he soon realized that this problem is too hard for him. Dimasik asks you to help him. The value may be very large, so find it modulo .
Input
The first line contains one integer (), the number of rational numbers Dimasik has.
Each of the following lines contains two integers and (, ), the numerator and denominator of the -th rational number.
Output
Print a single integer: the answer to the problem modulo .