Akash and GCD 2
Practice
4 (95 votes)
Approved
Data structures
Euler's totient function
Fenwick tree
Math
Medium
Number theory
Segment trees
Problem
18% Success 2088 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Akash is interested in a new function F such that,

\(F(x) = \frac{1}{GCD(1, x)} + \frac{2}{GCD(2, x)} + ... + \frac{x}{GCD(x, x)}\)

where \(GCD\) is the Greatest Common Divisor.

Now, the problem is quite simple. Given an array A of size N, there are 2 types of queries:

  1. C X Y : Compute the value of \(F(A[X] ) + F(A[X + 1]) + F(A[X + 2]) + .... + F( A[Y] ) \) (mod\( 10^9 + 7\))
  2. U X Y: Update the element of array \(A[X] = Y\)

Input:
First line of input contain integer N, size of the array.
Next line contain N space separated integers. Next line contain integer Q, number of queries.
Next Q lines contain one of the two queries.

Output:
For each of the first type of query, output the required sum (mod \(10^9 + 7\)).

Constraints:
\(1 \le N \le 10^6\)
\(1 \le Q \le 10^5\)
\(1 \le A[i] \le 5 * 10^5\)
For \(1^{st}\) type of query,
\(1 \le X \le Y \le N\)
For \(2^{nd}\) type of query
\(1 \le X \le N\)
\(1 \le Y \le 5 * 10^5\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
15 votes
Tags:
ApprovedEuler's totient functionMathMediumPrime FactorizationSieve
Points:30
Tags:
Totient FunctionGraphNumber theoryData StructuresAlgorithmsNumber TheoryMath