There are multiple test cases, terminated by a line "0 0 0 0 0".
For each test case, there is a line contains five numbers p (2<p<10^18, p is a prime number) ,x (0<=x<p), l, r (0<=l<=r<=10^18) and k (1<=k<=10^18).
3 0 1 2 1
233 23 2333 23333 23
233 1 1 2 23
0 0 0 0 0
Case #1: 2
Case #2: 36003
Case #3: 2097152