Order of Prime in Factorial
Difficulty: Hard

For a given prime $p$, define $\operatorname{ord}_p(k)$ as the multiplicity of $p$ in $k$, i.e. the number of times $p$ appears in the prime factorization of $k$.

For a given $p$ (prime) and $L$, let $F(p,L)$ be the number of integers $n$ such that $1 \le n \le L$ and $\operatorname{ord}_p(n!)$ is divisible by $p$. Here $n!$ denotes the factorial of $n$.

Your job is to calculate $F(p,L)$ given $p$ and $L$.

**Input Format**  
The first line contains the number of test cases $T$.   
Each of the next $T$ lines contains two integers $p$ and $L$ separated by a space.

**Output Format**  
For each test case, output one line containing $F(p,L)$.


**Constraints**  
$1 \le T \le 100000$  
$2 \le p \le 10^{18}$  
$1 \le L \le 10^{18}$  
$p$ is prime

**Sample input**  

    2
    2 6
    3 6
    

**Sample Output**  

    2
    2

**Explanation**   
Here are the first 6 factorials: 1, 2, 6, 24, 120, 720.  

The multiplicities of 2 in these numbers are: 0, 1, 1, 3, 3, 4.  
Exactly two of these are divisible by 2 (0 and 4), so $F(2,6) = 2$.

The multiplicities of 3 in these numbers are: 0, 0, 1, 1, 1, 2.  
Exactly two of these are divisible by 3 (0 and 0), so $F(3,6) = 2$.


Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:
#
# Complete the 'solve' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
#  1. LONG_INTEGER p
#  2. LONG_INTEGER l
#

def solve(p, l):
    # Write your code here




Reference solution (Python):
###Python 2  
```python  
def S(p,n):
    return 0 if n == 0 else (n%p) + S(p,n/p)

def G(p,L):
    Q,R = divmod(L,p)
    return Q + ((-S(p,Q)) % p < R)

def F_(p,L):
    Q,R = divmod(L,p)
    return p*G(p,Q) + R*(S(p,Q) % p == 0)

def F(p,L):
    return F_(p,L+1) - 1

for cas in xrange(input()):
    p,L = map(int, raw_input().strip().split())
    print F(p,L)
```