Minimal Coprime
시간 제한1초메모리 제한2048 MB
구간 [l, r]에 들어 있는 최소 서로소 구간의 개수를 구한다. 최소 서로소 구간은 [1, 2]와 1로만 이루어진 한 점 구간뿐이다.
문제
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 is called coprime if and are coprime1.
A coprime segment is called minimal coprime if it does not contain2 any coprime segment not equal to itself. To better understand this statement, you can refer to the notes.
Given , a segment of positive integers, find the number of minimal coprime segments contained in .
1Two integers and are coprime if they share only one positive common divisor. For example, the numbers and are not coprime because they are both divided by and , but the numbers and are coprime because their only positive common divisor is .
2A segment is contained in the segment if and only if .
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The only line of each test case consists of two integers and ().
출력
For each test case, output the number of minimal coprime segments contained in , on a separate line.
힌트
On the first test case, the given segment is . The segments contained in are as follows.
- : This segment is coprime, since the numbers and are coprime, and this segment does not contain any other segment inside. Thus, is minimal coprime.
- : This segment is coprime. However, as it contains , which is also coprime, is not minimal coprime.
- : This segment is not coprime because and share positive common divisors: and .
Therefore, the segment contains minimal coprime segment.