编程介的小学生 2019-05-09 16:39 采纳率: 20.5%
浏览 195

序列三元组的除法的算法,怎么采用C程序的的语言的代码的编写的过程去实现的?

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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!