A Mathematics problem
Practice
3.8 (10 votes)
Algorithms
Math
Number theory
Number theory
Prime factorization
Problem
24% Success 1975 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a pseudocode that determines the value of the following function \(f(p,q,n)\):  

def f(p,q,n):
    ans=0
    for (i from 1 to n)                          // for loop1
        for (all primes m between p and q )      // for loop2(both p and q inclusive)
            for  (j from 1 to (n/i) )            // for loop3((n/i) does integer division)
                for  (all divisors d of (m*j) )  // for loop4
                    val = ftemp(d)/d             // Not a integer division
                    if(j is odd)
                    ans = ans - val*m*j
                    else
                    ans = ans + val*m*j
    return ans

def ftemp(d): 
    if(d==1)
       return 1
    temp = 0
    for (all prime factors p of d)
        if( d%(p*p) ==0 ) return 0;
        temp = temp+1
    if (temp is even) 
        return 1
    return -1

It can take a large amount of time to write and execute such a lengthy code. Your task is to determine the value of function \(f(p,q,n)\). The value must be modulo \(1000000007\).

Input format

  • First line: \(t\) denoting the number of test cases
  • Next \(t\) lines: Three space-separated integers \(p\), \(q\), and \(n\)

Output format

For each test case, print a single line containing answer.\(f(p,q,n) \mod (10^9+7)\).

Constraints

\(1 \le t \le 10 \)

\(2< p<q<10^5\)

\(1 \le n \le 10^9\)

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:50
16 votes
Tags:
CombinatoricsMathNumber Theory
Points:50
36 votes
Tags:
Basic Number Theory-2AlgorithmsMathNumber Theory