Counting TermsProblem code: TERM |
All submissions for this problem are available.
When the Chef is not busy with cooking delicious foods, one of his favorite pastime is to solve mathematical problem. But as you know, he is not very good with programming. So when he fails to solve a problem he usually asks John to write a program that will solve it.
Recently the chef became interested in finding the expansion of (x1+x2+....+xk)n. Specifically he is more interested in number of terms in it. Being unable to solve the problem he asked John for help. The conversation between John and chef goes as
Chef: Can you write a program that will calculate f(n,k)= number of terms in (x1+x2+....+xk)n ?
John: That is a very easy problem.
Chef: Oh, really? Then calculate the sum over (i=0 to n) (f(i,k))
John: That is also an easy problem.
Chef: Then go finish it. And did I mention that I am calculating modulo a prime number p.
John: What?
Chef: Say k=2, n=4, p=3. Then (x1+x2)4 %3 = (x14+4 x13 x2+6 x12 x22+ 4 x1 x23 + x24) %3 = (x14+ x13 x2 + x1 x23 + x24) %3. So if p=3 then f(4,2)=4.
John: OK, I am doing it.
As John started to solve the problem he realized it is not that easy. Now he asked you, his best friend, for help.
As the answer can be quite large print the output modulo 1000003.
Input
Input file starts with a line containing a number T. T lines follow each describing a test case. Each test case consists of a line containing three space separated integers n, k, p.
Output
Output T lines, each line containing the Sum over (i=0 to n) f(i,k) for the given prime p modulo 1000003.
Limit:
1<=T<=10000
0<=n<=10^15
1<=k<=10^15
1<=p<=100
p prime number
Example
Input: 7 10 2 2 10 2 3 10 3 2 10 3 3 4 2 3 3 2 3 0 2 2 Output: 37 42 85 112 12 8 1
| Author: | tanaeem |
| Date Added: | 3-01-2011 |
| Time Limit: | 10 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

If f(n,k) is the number of
same problem here. how could