#P11089. [2016杭电多校]Easy Homework
[2016杭电多校]Easy Homework
Easy Homework
Problem Description
Let’s consider a sequence which satisfies following 2 conditions. 1.. 2.,for any integer . Here A is a constant integer. Given a prime and an integer , your task is to calculate , i.e. the number of indices between and such as .
Input
There are several test cases. The first line of the input contains an integer , the number of test cases. Each of the next lines contains 5 integers, $A,p,x,L,R(0\leq A < 10^9,2<p<10^9,0\leq x < p,1\leq L\leq R \leq 10^{18})$
Output
Print lines, containing the answer to the problem.
Sample Input
2
1 5 0 1 5
2 29 12 3 6
Sample Output
1
2
Author
金策工业综合大学(DPRK)
Source
2016 Multi-University Training Contest 9