CF1342C C. Yet Another Counting Problem [ lcm ]
C. Yet Another Counting Problem
You are given two integers a and b, and q queries. The i-th query consists of two numbers li and ri, and the answer to it is the number of integers x such that $li≤x≤ri$, and $((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$. Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3=2, 7 mod 8=7 , 9 mod 4=1, 9 mod 9=0.
Input
The first line contains one integer t (1≤t≤100) — the number of test cases. Then the test cases follow.
The first line of each test case contains three integers a, b and q (1≤a,b≤200; 1≤q≤500).
Then q lines follow, each containing two integers li and ri $(1≤li≤ri≤10^{18})$ for the corresponding query.
Output
For each test case, print q integers — the answers to the queries of this test case in the order they appear.
Example
input
1 | 2 |
output
1 | 0 0 0 2 4 |
$((x \bmod a) \bmod b) , ((x \bmod b) \bmod a)$ 的值以 lcm(a,b) 周期性变化。统计每一个周期中不一样的个数 cnt
对于一个数 x , (x/k) * cnt + f[x % k] = ans;
1 | int t; |