#P9853. [入门赛 #17] 方程求解
[入门赛 #17] 方程求解
Problem Description
Xiao A has equations about . The -th equation is in the form . The solutions are all positive integers. For example, the following equations all meet the requirement:
2x+4=10
-3x+13=10
4x-8=16
Among them, the solution to the first equation is , the solution to the second equation is , and the solution to the third equation is .
Xiao A wants to know: given , within the range , how many positive integers satisfy that is a solution to at least one of the equations. To prevent you from tricking him, he will ask you times.
Input Format
The first line contains two positive integers , representing the number of equations Xiao A has and the number of queries he will ask.
Starting from the second line, the next lines each contain a string describing an equation.
Starting from line , the next lines each contain two positive integers , representing one query: given , ask how many positive integers in the range satisfy that is a solution to at least one of the equations.
Output Format
For each query, output one line with one integer, indicating how many positive integers in the range satisfy that is a solution to at least one of the equations.
3 4
2x+4=10
-3x+13=10
4x-8=16
1 6
1 8
3 6
4 5
3
3
2
0
5 3
5x-2=13
8x+5=45
4x-12=8
-2x+10=4
3x-7=2
1 3
1 5
3 5
1
2
2
Hint
[Sample Explanation]
For the first sample group, it is the example given in the statement. The solutions of the three equations are . Then:
- For the range , there are values of () that are solutions to at least one equation.
- For the range , it is the same as above.
- For the range , there are values of () that are solutions to at least one equation.
- For the range , there is no that is a solution to at least one equation.
- Therefore, the outputs are .
For the second sample group, the solutions of the five equations are . Then:
- For the range , only is a solution to at least one equation.
- For the range , there are values of () that are solutions to at least one equation.
- For the range , there are values of () that are solutions to at least one equation.
- Therefore, the outputs are .
[Constraints]
The testdata guarantees that . In each equation, satisfy , and the solution of each equation must be a positive integer. In each query, satisfy .
The input size is large, so please pay attention to the efficiency of input and output in your code.
Translated by ChatGPT 5