[原创]HDU 5446 Unknown Treasure [lucas+CRT]【数论】
[原创]HDU 5446 Unknown Treasure [lucas+CRT]【数论】
2016-08-11 20:13:29 Tabris_ 阅读数:224
博客爬取于2020-06-14 22:43:52
以下为正文
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/52186122
题目连接:传送门
------------------------------.
Unknown Treasure
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2196 Accepted Submission(s): 814
Problem Description
On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, she found a treasure chest with a combination lock and some numbers on it. After quite a research, the mathematician found out that the correct combination to the lock would be obtained by calculating how many ways are there to pick m different apples among n of them and modulo it with M. M is the product of several different primes.
Input
On the first line there is an integer T(T≤20) representing the number of test cases.
Each test case starts with three integers n,m,k(1≤m≤n≤10^18,1≤k≤10) on a line where k is the number of primes. Following on the next line are k different primes p1,…,pk. It is guaranteed that M=p1⋅p2⋅⋅⋅pk≤10^18 and pi≤10^5 for every i∈{1,…,k}.
Output
For each test case output the correct combination on a line.
Sample Input
1
9 5 2
3 5
Sample Output
6
------------------------------.
题目大意:
就是求C(n,m)%M ,M= p1p2p3p4…*pn;
题目解释:
大组合数就是用lucas定理求解
而lucas要求是对质数取模的时候才成立
所以分别对p[i] 进行求解 然后构成了一个同余方程组
用中国剩余定理求解就行了
注意大数乘法的时候可能会爆longlong 所以要用快速乘
附本题代码
------------------------------.
1 | # include <stdio.h> |