hdu3037 lucas 定理 组合数取模
2015-09-02 09:56
218 查看
#include<stdio.h> #include<string> #include<map> #include<vector> #include<cmath> #include<stdlib.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; #define rep0(i,n) for(int i=0;i<n;i++) #define rep(i,j,k) for(int i=j;i<k;i++) const int N=1e5+10; const int MOD=1e9+7; int n,m,k,up,p; int A ; int inv ; long long qmod(long long a,long long b){ long long res=1; while(b){ if(b&1) res=res*a%p; a=a*a%p; b>>=1; } return res; } int get(int a,int b){ long long n=1,m=1; while(b){ n=n*a%p; m=m*b%p; a--,b--; } return n*qmod(m,p-2)%p; } int solve(int a,int b){ long long res=1; while(b){ res=res*get(a%p,b%p)%p; a/=p;b/=p; } return res; } int main(){ #ifndef ONLINE_JUDGE freopen("aaa","r",stdin); #endif int T; scanf("%d",&T); while(T--){ scanf("%d%d%d",&n,&m,&p); int a=n+m; int b=n; printf("%d\n",solve(a,b)); } return 0; }
相关文章推荐
- 字符串之把char类型组成的字符串循环右移n位
- WMI Backdoor 三好学生
- [转]用Android自带的signapk.jar 签名应用程序
- iOS多线程——GCD
- 实例讲解临时处理去重 80w 数据时夯死现象
- ppt转为pdf文档格式转换的方法讲解
- redhat linux yum源修改
- 解决easyUI前端排序效果针对数字类型的排序出现仅首位数字排序的情况
- Eclipse 扩大内存
- AsyncTask
- 在Eclipse中使用JUnit4进行单元测试(中)
- 大数据也要有自已的特色
- std空间和全局命名空间
- Connection is read-only. Queries leading to data modification are not allowed
- centos与windows共享文件夹
- hdu5319 Painter(模拟)
- 在Eclipse中使用JUnit4进行单元测试(上)
- SQL NULL 的问题
- mysql 向上取整
- javascript学习总结之js使用技巧