Time limit: 1s
Memory limit: 256MB
Input: morcovi.in
Output: morcovi.out
Task
Andrei has carrots, conveniently numbered from to , and a favorite number .
Two carrots and are compatible if , where:
- represents the greatest common divisor of the numbers and ;
- represents the least common multiple of the numbers and .
In how many ways can Andrei choose two carrots and () such that they are compatible?
Input data
Each test contains multiple test cases. On the first line of the input file morcovi.in
will be the number of test cases .
Each test case consists of two numbers and — the number of Andrei's carrots and Andrei's favorite number, respectively.
Output data
For each test case, print the number of ways Andrei can choose two carrots and () such that they are compatible in the output file morcovi.out
.
Constraints and clarifications
- To obtain points for a particular subtask, at least one submitted source code will have to pass all the tests of that subtask.
# | Points | Constraints |
---|---|---|
0 | 0 | Example |
1 | 25 | |
2 | 21 | |
3 | 18 | |
4 | 12 | |
5 | 24 | No additional constraints |
Example
morcovi.in
5
1000000000 1
30 6
6 10
420 69
123456789 987654321
morcovi.out
1
4
1
8
54
Explanation
- In the first test case, the only way to choose the carrots is and .
- In the second test case, the ways to choose the carrots are: , , , and .
- In the third test case, the only way to choose the carrots is and .
- In the fourth test case, the ways to choose the carrots are: , , , , , , , and .