DIVCNTK - Counting Divisors (general)

Let σ0(n)\sigma_0(n) be the number of positive divisors of nn.

For example, σ0(1)=1\sigma_0(1) = 1, σ0(2)=2\sigma_0(2) = 2 and σ0(6)=4\sigma_0(6) = 4.

Let Sk(n)=i=1nσ0(ik).S_k(n) = \sum _{i=1}^n \sigma_0(i^k).

Given nn and kk, find Sk(n)mod264S_k(n) \bmod 2^{64}.

Input

There are multiple test cases. The first line of input contains an integer TT (1T100001 \le T \le 10000), indicating the number of test cases. For each test case:

The first line contains two integers nn and kk (1n,k10101 \le n, k \le 10^{10}).

Output

For each test case, output a single line containing Sk(n)mod264S_k(n) \bmod 2^{64}.

Example

Input:
5
1 3
2 3
3 3
10 3
100 3

Output:
1
5
9
73
2302

Information

There are 5 Input files.

  • Input #1: 1n100001 \le n \le 10000, TL = 1s.
  • Input #2: 1T300, 1n1071 \le T \le 300,\ 1 \le n \le 10^7, TL = 5s.
  • Input #3: 1T75, 1n1081 \le T \le 75,\ 1 \le n \le 10^{8}, TL = 5s.
  • Input #4: 1T15, 1n1091 \le T \le 15,\ 1 \le n \le 10^{9}, TL = 5s.
  • Input #5: 1T5, 1n10101 \le T \le 5,\ 1 \le n \le 10^{10} , TL = 5s.

My C++ solution runs in 5.6 sec. (total time)

Notes

This is general version of DIVCNT1, DIVCNT2 and DIVCNT3. You may want to solve these three problems first.


Added by:zimpha
Date:2018-01-11
Time limit:1s-5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2018-01-14 04:45:47 zimpha
@[Rampage] Blue.Mary
Input:
1
1000 42

Output:
149315662
2018-01-14 03:04:26 [Rampage] Blue.Mary
Please provide one test with k != 1,2,3.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.