time limit per test
1 second
memory limit per test
256 megabytes
Today, Little John used all his savings to buy a segment. He wants to build a house on this segment.
A segment of positive integers [l,r][l,r] is called coprime if ll and rr are coprime∗∗.
A coprime segment [l,r][l,r] is called minimal coprime if it does not contain†† any coprime segment not equal to itself. To better understand this statement, you can refer to the notes.
Given [l,r][l,r], a segment of positive integers, find the number of minimal coprime segments contained in [l,r][l,r].
∗∗Two integers aa and bb are coprime if they share only one positive common divisor. For example, the numbers 22 and 44 are not coprime because they are both divided by 22 and 11, but the numbers 77 and 99 are coprime because their only positive common divisor is 11.
††A segment [l′,r′][l′,r′] is contained in the segment [l,r][l,r] if and only if l≤l′≤r′≤rl≤l′≤r′≤r.
Input
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001≤t≤100). The description of the test cases follows.
The only line of each test case consists of two integers ll and rr (1≤l≤r≤1091≤l≤r≤109).
Output
For each test case, output the number of minimal coprime segments contained in [l,r][l,r], on a separate line.
Example
Input
Copy
6
1 2
1 10
49 49
69 420
1 1
9982 44353
Output
Copy
1 9 0 351 1 34371
Note
On the first test case, the given segment is [1,2][1,2]. The segments contained in [1,2][1,2] are as follows.
- [1,1][1,1]: This segment is coprime, since the numbers 11 and 11 are coprime, and this segment does not contain any other segment inside. Thus, [1,1][1,1] is minimal coprime.
- [1,2][1,2]: This segment is coprime. However, as it contains [1,1][1,1], which is also coprime, [1,2][1,2] is not minimal coprime.
- [2,2][2,2]: This segment is not coprime because 22 and 22 share 22 positive common divisors: 11 and 22.
Therefore, the segment [1,2][1,2] contains 11 minimal coprime segment.
解题说明:此题是一道数学题,找规律能发现即相邻数组成的区间互质,那么一段区间的互质区间数就为R-L,如果R和L相等,答案就是1.
#include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int l, r;
scanf("%d %d", &l, &r);
if (l == r && l == 1)
{
printf("1\n");
}
else
{
printf("%d\n", r - l);
}
}
return 0;
}