Super functions

4.2

28 votes
Mathematics, Medium-Hard
Problem

View Russian Translation

For two integers a and b, integer d is their common divisors if and only if d divides both a and b. For example, 9 is a common divisor of 18 and 27, while 6 is not.

Among all common divisors of two integers a, b there always exists the largest one. Such a divisor is call the greatest common divisor, often denoted as gcd(a,b), and it is one of the most fundamental concepts in number theory.

This problem focuses on gcd function.

For a given integer Q the task is to answer Q queries, each one defined by a single integer n:

  1. superpowers(n):=ni=1nigcd(i,n)
  2. superexps(n):=ni=12n+igcd(i,n)
  3. superphis(n):=ni=1φ(ni)gcd(i,n)

where φ(m) is called Euler’s totient function and it counts the positive integers jm, for which gcd(m,j)=1. For example, φ(4)=2, because there are two integers not greater than 4, for which their greatest common divisor with 4 is 1, these numbers are 1 and 3.

Since all the above values can be very large, the goal is to compute their values modulo 109+7.

Input format:

In the first line there is a single integer Q denoting the number of queries. In each of the following Q lines there are two integers t and n, where t is either 1,2 or 3 and denotes the type of the query, and n denotes the parameter of the query.

Output format:

Output exactly Q lines. In the ith of them output the answer to the ith query computed modulo 109+7.

Constraints:

1Q105
1N105

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

There are 3 test cases to handle:

For the first query, superpowers(4), the answer is equal to:

41gcd(1,4)+42gcd(2,4)+43gcd(3,4)+44gcd(4,4)=1124

For the second query, superexps(4), the answer is equal to:

24+1gcd(1,4)+24+2gcd(2,4)+24+3gcd(3,4)+24+4gcd(4,4)=1312

For the third query, superphis(4), the answer is equal to:

φ(41)gcd(1,4)+φ(42)gcd(2,4)+φ(43)gcd(3,4)+φ(44)gcd(4,4)=562

Editor Image

?