tjut 3037
来源:互联网 发布:淘宝天下 电话号码 编辑:程序博客网 时间:2024/06/05 04:53
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>using namespace std;typedef long long lld;lld n, m, p;lld Ext_gcd(lld a,lld b,lld &x,lld &y){ if(b==0) { x=1, y=0; return a; } lld ret= Ext_gcd(b,a%b,y,x); y-= a/b*x; return ret;}lld Inv(lld a,int m){ ///求逆元 lld d,x,y,t= (lld)m; d= Ext_gcd(a,t,x,y); if(d==1) return (x%t+t)%t; return -1;}lld Cm(lld n, lld m, lld p) ///组合数学{ lld a=1, b=1; if(m>n) return 0; while(m) { a=(a*n)%p; b=(b*m)%p; m--; n--; } return (lld)a*Inv(b,p)%p; ///(a/b)%p 等价于 a*(b,p)的逆元}int Lucas(lld n, lld m, lld p) ///把n分段递归求解相乘{ if(m==0) return 1; return (lld)Cm(n%p,m%p,p)*(lld)Lucas(n/p,m/p,p)%p;}int main(){ int T; cin >> T; while(T--) { scanf("%lld%lld%lld",&n,&m,&p); printf("%d\n",Lucas(n+m,m,p)); } return 0;}
0 0
- tjut 3037
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- HTML5(李炎恢)学习笔记三 ------------- HTML5元素(上)
- CSS3
- DailyLine Share
- 23种设计模式C++实例之模板方法模式
- Android 密码输入 EditText
- tjut 3037
- HDU 1221
- 面向对象
- shiro 使用缓存时出现:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
- 国家城市二级联动jsp页面
- 仅需五步,制作专属你的网站
- C++函数对象的应用
- Retrofit初体验
- 完全搞定iframe(框架)里的滚动条