Skip to content

lakhaNamdhari/Euler-Totient-Function-Extended

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Euler-Totient-Function-Extended

Euler totient function (denoted by phi(N)) for a positive integer N is defined as number of positive integers less than or equal N that are coprime to N.

Let's generalize this concept of Euler totient function. For positive integer N let's write out the integers that are less than or equal to N and are coprime to N. We'll get a list of integers of the form A1, A2, ..., AM, where M = phi(N). Let's denote EK(N) = A1K + A2K+...+AMK. This way we obtain something more general version of Euler totient function, in particular, E0(N) = phi(N) for every positive integer N. Task is to calculate EK(N). As answer could be large, print the answer modulo 109+7

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains two space separated integers N and K.

Output

For each test case, output a single line containing the answer to the problem i.e. the value of EK(N) modulo 109+7.

Constraints

1 ≤ T ≤ 128
Subtask 1
1 ≤ N ≤ 10^4
0 ≤ K ≤ 10^4
Subtask 2
1 ≤ N ≤ 10^12
K = 0
Subtask 3
1 ≤ N ≤ 10^12
K = 1
Subtask 4
1 ≤ N ≤ 10^12
0 ≤ K ≤ 256

About

Extended implementation of Euler Totient Function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published