The output of a function
Practice
1.1 (16 votes)
Combinatorics
Math
Number theory
Problem
45% Success 448 Attempts 50 Points 4s Time Limit 256MB Memory 1024 KB Max Code
You are given the following pseudocode that determines the value of a function \(f(p,q,r)\):
def f(p,q,r):
ans=0
for(int i=0;i<=p;i++) {
temp = 0
for(int j=1;j<=q;j++) {
ta = pow(r,i); // where pow() is the power function
tb = (ta-1)/ta
temp + = pow(tb,j);
}
temp2 = fact(p)/(fact(p-i)*fact(i)) // where fact() is the factorial function
if(i&1) ans-=temp*temp2;
else ans+=temp*temp2;
}
return ans
Your task is to determine the value of function \(f(p,q,r)\).
Input format
- The first line contains \(t\) denoting the number of test cases.
- Next \(t\) lines contain three space-separated integers \(p\), \(q\), and \(r\).
Output format
\(f(p,q,r) \) can be represented as \(n \over m\). For each test case, print a single line containing answer \((n*m^{-1})\%1000000007 \), that is, the modulo inverse.
Constraints
\(1 \le t \le 10 \)
\(1\le p,\ q\le10000\)
\(2 \le r \le 5\)
Explanation
.After putting the values in the function we get \(63/448\) as output and taking modulo inverse we get \(265625002\)
Code Editor
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
Submissions
Please login to view your submissions
Similar Problems
Points:50
36 votes
Tags:
Basic Number Theory-2AlgorithmsMathNumber Theory
Points:50
10 votes
Tags:
AlgorithmsMathNumber TheoryNumber theoryPrime Factorization
Editorial
Login to unlock the editorial
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