LightOj 1067(Lucas)
来源:互联网 发布:vc tcp socket编程 编辑:程序博客网 时间:2024/05/24 15:36
lightoj 1067
题目大意:
求:
思路:
Lucas定理,组合打表
#include <iostream>#include <cstdio>#define LL long long#define MOD 1000003#define N 1000005using namespace std;LL f[N];void init(LL p){ f[0] = 1; for (int i = 1; i <= p; i++) { f[i] = f[i - 1] * i % p; }}LL quick_Mod(LL m, LL n, LL k) { LL ans = 1; while (n) { if (n & 1) { ans = (ans * m) % k; } n = n >> 1; m = (m * m) % k; } return ans;}// LL Comb(LL a, LL b, LL p)// {// if (a < b)// {// return 0;// }// else if (a == b)// {// return 1;// }// else if (b > a - b)// {// b = a - b;// }// LL ca = 1, cb = 1, ans = 1;// for (LL i = 0; i < b; i++)// {// ca = (ca * (a - i)) % p;// cb = (cb * (b - i)) % p;// }// ans = (ca * quick_Mod(cb, p - 2, p)) % p;// return ans;// }LL Lucas(LL n, LL m, LL p){ LL ans = 1; while (n && m && p) { // ans = (ans * Comb(n % p, m % p, p)) % p; LL a = n % p; LL b = m % p; if (a < b) { return 0; } ans = (ans * f[a] * quick_Mod(f[b] * f[a - b] % p, p - 2, p)) % p; n /= p; m /= p; } return ans;}int main(){ init(MOD); int T; scanf("%d", &T); for (int cas = 1; cas <= T; cas++) { LL n, m; scanf("%lld%lld", &n, &m); LL ans = Lucas(n, m, MOD); printf("Case %d: %lld\n", cas, ans); } return 0;}
0 0
- LightOj 1067(Lucas)
- LightOJ 1067 - Combinations【Lucas定理】
- Lightoj 题目1067 Combinations(lucas)
- LightOJ 1067 - Combinations (Lucas定理)
- 【LightOJ】1067 - Combinations(Lucas & 逆元)
- 数学学习小记(二) 组合数求模:Lucas 定理 LightOJ 1067 + Hdu 3037
- [容斥+lucas] LightOJ 1124 - Cricket Ranking
- lucas
- LUCAS
- lucas
- Lightoj 1067
- codeforces - E. Devu and Flowers & LightOJ 1124 Cricket Ranking(容斥定理+lucas定理)
- LightOJ 1067 组合数求模
- lightOJ 1067 - Combinations
- lightoj 1067 - Combinations
- LightOJ 1067 Combinations
- LightOJ
- LightOJ
- 弱网测试,你一定会发现新大陆
- SSO之CAS单点登录实例演示
- nodejs中流(stream)的理解
- Android EditText实时监听
- 【结论】【数论】欧拉定理
- LightOj 1067(Lucas)
- Unsupported major.minor version 52.0
- Android中visibility属性VISIBLE、INVISIBLE、GONE的区别
- OpenWrt目录结构
- mybatis 入门
- Nginx负载均衡+tomcat+session共享
- 追踪app崩溃率
- JQuery 00001
- s2sh整合之注解方式