eolymp
bolt
Try our new interface for solving problems
Problems

Another New Function

Another New Function

The totient function ϕ(n) or phi(n), also called Euler's totient function, is defined as the number of positive integers ≤ n that are relatively prime to (i.e., do not contain any factor in common with) n, where 1 is counted as being relatively prime to all numbers. Since a number less than or equal to and relatively prime to a given number is called a totative the totient function ϕ(n) can be simply defined as the number of totatives of n. For example, there are eight totatives of 24 (1, 5, 7, 11, 13, 17, 19 and 23), so ϕ(24) = 8.

The depth of phi value of a number is denoted by the number of steps required before it reaches 1. An example will make it very clear.

  • ϕ(13) = 12 . . . step 1

  • ϕ(12) = 4 . . . step 2

  • ϕ(4) = 2 . . . step 3

  • ϕ(2) = 1 . . . step 4

So the depth of phi(13) is 4. We name this function as depthphi. So we can write depthphi(13) = 4. The sum of depthphi function (SODF) takes two integers as parameter and its definition is given below:

prb10721.gif

Given the value of m and n your job is to find the value of SODF(m, n).

Input

The first line contains an integer n (0 < n < 2001) which indicates how many tests are there. Each of the next n lines contains two integers m and n (2mn2000000).

Output

For each test case produce one line that contains an integer, which actually denotes the value of SODF(m, n).

Time limit 1 second
Memory limit 128 MiB
Input example #1
2
2 10
100000 200000
Output example #1
22
1495105