GithubHelp home page GithubHelp logo

gabrielpeart / euler-totient-function-extended Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lakhanamdhari/euler-totient-function-extended

0.0 0.0 0.0 160 KB

Extended implementation of Euler Totient Function

License: MIT License

JavaScript 100.00%

euler-totient-function-extended's Introduction

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

euler-totient-function-extended's People

Contributors

lakhanamdhari avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.