F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1032    Accepted Submission(s): 388


Problem Description
As you know, there number of permutation of the increasing vector {1, 2, 3¡­n} is exactly n! ;For example, if n = 3, then, {1,2,3} , {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1} are all the permutation of the vector {1,2,3 };
  We define D( {A1,A2,¡­An} ) = the number of element that satisfy Ai=i
  For example, D( {1,2,3} ) = 3 ,D( {1,3,2} ) = 1 (only ¡®1¡¯ is at 1), D({3,1,2}) = 0 ¡­.
  Now we want to calculate the number of permutation that satisfy D( {A1,A2,¡­An} ) = K.
  For example, if n = 3 and k = 3, then of course there is only one permutation {1,2,3} that satisfy D( {1,2,3}) = 3. But if n = 3 and k = 0, then there are two permutations {3,1,2} and {2,3,1} satisfy D( {3,2,1} ) = D( {2,3,1} ) = 0;
  But when n is very large, it¡¯s hard to calculate by brute force algorithm. Optimal is one required here.
  Because the answer may be very large, so just output the remainder of the answer after divided by m.
 

Input
In the first line there is an integer T, indicates the number of test cases. (T <= 500)
In each case, the first line contains three integers n,k and m. (0 <= k<= n <=10^9, 1 <= m <= 10^5, n != 0)
 

Output
Output ¡°Case %d: ¡°first where d is the case number counted from one. Then output the remainder of the answer after divided by m.
 

Sample Input
2 3 0 7 3 3 3
 

Sample Output
Case 1: 2 Case 2: 1
 

Author
AekdyCoin
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 10:27:47, Gzip enabled