|
||||||||||
The Diary of Math TeacherTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 157 Accepted Submission(s): 52 Problem Description 03/21/2010 SUN Sunny ¡°Hi, boys and girls ,today we will learn the ¡°Deference¡± .¡± ¡°What is the ¡°Deference¡±? Is that difficult? ¡± ¡°Boys , don¡¯t worry, and you will know it immediately.¡± ¡°f(x) is an function, and x is an integer. ¦¤f( x ) = f (x + 1 ) ¨C f( x ) ¡± ¡°In general, ¦¤(n+1)f( x ) = ¦¤(n)f( x+1 ) - ¦¤(n)f( x )¡± ¡°In particular, ¦¤(0)f( x ) = f( x )£¬¦¤(1)f( x ) = ¦¤f (x )¡± ¡°Do you understand?¡± ¡°No!!!!!!!!!!!!¡± ¡°Does anyone understand?¡± ¡°Only you our teacher!¡± ¡°How dare you be so ironic. Since you all have learnt the Factorial. I will give you a problem of factorial and difference. Anyone who can¡¯t solve it will be severely punished¡± ¡° The problem is: Given a nonnegative integer array {a[n]} , and each of its elements a[i] (1<=i<=n)is also known. f(x)=¡Ç{1<=i<=n}(x+a[i]) Your task is to calculate ¦¤(k)f(0)/k! ¡± Damn it,really bad mood. Well, I'd better go to sleep now. Input Multiple test cases. The first line of each test case will be 3 integers : n(1<=n<=1000) , k(0<=k<=n-1) , p(1<=P<=20000). The following line will contain n integers a[i] (0<=a[i]<=20000). Input ends with n=k=p=0. Output For each test case ,pint the answer mod p in one separate line. The last case n=k=p=0 does not need to be processed. Sample Input
Sample Output
Hint In the first test case: f( x ) = ¡Ç{1<=i<=5}(x + a[i]) = (x + a[1])(x + a[2])(x + a[3])(x + a[4])(x + a[5]) = (x + 1)*x*x*(x + 1)*x So , f(0) = 0 , f(1) = 4 , f(2) = 72 , f(3) = 432 ¦¤f(0) = 4 , ¦¤f(1) = 68 , ¦¤f(2) = 360 ¦¤(2)f(0) = 64 , ¦¤(2)f(1) = 292 ¦¤(3)f(0) = 228 3! = 1*2*3 = 6 228/6 = 38 Source | ||||||||||
|