Unknown Treasure HDU
来源:互联网 发布:剑三正太脸型数据网盘 编辑:程序博客网 时间:2024/06/05 19:22
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 mm different apples among nn of them and modulo it with MM. MM is the product of several different primes.
Input
On the first line there is an integer
Each test case starts with three integers
Output
For each test case output the correct combination on a line.
Sample Input
1
9 5 2
3 5
Sample Output
6
这个大数取模,而且都是素数并且两两不等,而且素数的范围在5次方内
#include<cstdio>#include<algorithm>#include<cmath>#include<iostream>#include<stack>#include<vector>#include<cstring>#define N 1005#define INF 0x3f3f3f3ftypedef long long ll;using namespace std; ll fac[100005];ll n,m,k;ll p[15];ll r[15];ll P(ll a,ll b,ll mod){ ll ans=1; a%=mod; while(b) { if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans;}ll comb(ll n,ll m,ll mod){ if(n<m) return 0; return fac[n]*P(fac[m]*fac[n-m],mod-2,mod)%mod;}ll Lucas(ll n,ll m,ll mod){ if(!m)return 1; if(n==m)return 1; return Lucas(n/mod,m/mod,mod)*comb(n%mod,m%mod,mod)%mod;}ll getR(ll mod){ for(int i=1;i<mod;i++) fac[i]=fac[i-1]*i%mod; return Lucas(n,m,mod);}ll modmul(ll a, ll b, ll MOD) { ll ret = 0; while(b) { if(b & 1) ret = (ret + a) % MOD; a = (a + a) % MOD; b >>= 1; } return ret;}ll CRT(){ ll M=1; for(int i=1;i<=k;i++) M*=p[i]; ll ans=0; ll temp; for(int i=1;i<=k;i++) { temp=P(M/p[i],p[i]-2,p[i]); temp=modmul(temp,r[i],M); temp=modmul(temp,M/p[i],M); ans=(ans+temp)%M; } return ans;}int main(){ fac[0]=1; int t; scanf("%d",&t); while(t--) { scanf("%lld%lld%lld",&n,&m,&k); for(int i=1;i<=k;i++) { scanf("%lld",p+i); r[i]=getR(p[i]); } printf("%lld\n",CRT()); } return 0;}
- HDU 5446 Unknown Treasure
- HDU 5446 Unknown Treasure
- HDU 5446 Unknown Treasure
- HDU 5446 Unknown Treasure
- HDU 5446 Unknown Treasure
- HDU 5446 Unknown Treasure
- HDU 5446 Unknown Treasure
- Unknown Treasure HDU
- HDU 5446 Unknown Treasure(Lucas定理+CRT)
- HDU 5446 Unknown Treasure Lucas+CRT
- HDU 5446 Unknown Treasure [lucas+CRT]【数论】
- HDU 5446 Unknown Treasure(Lucas定理+中国剩余定理)
- hdu 5446 Unknown Treasure(lucas+中国剩余定理)
- hdu 5446 Unknown Treasure (Lucas定理+CRT+快速乘)
- HDU 5446 Unknown Treasure(CRT+lucas定理)
- HDU 5446-Unknown Treasure(Lucas+中国剩余定理)
- hdu 5446 Unknown Treasure(lucas定理+中国剩余定理)
- hdu 5446 Unknown Treasure(Lucas定理+中国剩余定理)
- python 模拟Http请求
- 在MyEclipse中启动Tomcat报错Error initializing endpoint java.net.SocketException: Unrecognized Windows Sock
- 观察者模式与回调
- SourceInsight下载、安装、破解、主题修改、其他配置全过程
- 2017.09.21--env环境变量
- Unknown Treasure HDU
- python-xml.etree.ElementTree解析xml文件
- 不同地间,不同元器件作用
- Android 输入法键盘管理
- Java jsonp跨域问题
- 最简单的web单点登录(SSO)
- oracle与mysql group by区别
- RxJava 2.x入门教程
- LintCode 46.主元素