FZU 2020 :组合 【lucas】
Problem Description
思路:水题,练一下lucas
#include<iostream>
#include<cstdio>
#include <math.h>
#include<algorithm>
#include<string.h>
#include<queue>
#define MOD 1000003
#define maxn 2009
#define LL long long
using namespace std;
LL mpow(LL a,LL n,LL p)
{
if(n==0)return 1;
if(n==1)return a%p;
if(n&1)return (a*mpow(a,n-1,p))%p;
else
{
LL u=mpow(a,n>>1,p)%p;
return (u*u)%p;
}
}
LL C(LL n,LL m,LL p)
{
if(m==0)return 1;
if(m>n-m)m=n-m;
LL up=1,down=1;
for(int i=1;i<=m;i++){
up=(up*(n-i+1))%p;
down=(down*i)%p;
}
return up*mpow(down,p-2,p)%p;
}
long long lucas(long long n,long long m,long long p)
{
if(m==0)return 1;
return C(n%p,m%p,p)*lucas(n/p,m/p,p);
}
int main()
{
long long m,n,p;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%I64d%I64d%I64d",&n,&m,&p);
printf("%I64d\n",lucas(n,m,p));
}
return 0;
}
FZU 2020 :组合 【lucas】的更多相关文章
- FZU 2020 组合 (Lucas定理)
题意:中文题. 析:直接运用Lucas定理即可.但是FZU好奇怪啊,我开个常数都CE,弄的工CE了十几次,在vj上还不显示. 代码如下: #pragma comment(linker, "/ ...
- FZU 2020 组合
组合数求模要用逆元,用到了扩展的欧几里得算法. #include<cstdio> int mod; typedef long long LL; void gcd(LL a,LL b,LL ...
- lucas定理 FOJ 2020 组合
Problem 2020 组合 Accept: 886 Submit: 2084Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...
- Problem 2020 组合(FOJ)
Problem 2020 组合 Accept: 714 Submit: 1724Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...
- 【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas
[题目]BZOJ 2111 [题意]求有多少1~n的排列,满足\(A_i>A_{\frac{i}{2}}\),输出对p取模的结果.\(n \leq 10^6,p \leq 10^9\),p是素数 ...
- 【Lucas组合数定理】组合-FZU 2020
组合 FZU-2020 题目描述 给出组合数C(n,m), 表示从n个元素中选出m个元素的方案数.例如C(5,2) = 10, C(4,2) = 6.可是当n,m比较大的时候,C(n,m)很大!于是x ...
- 组合 Lucas定理
组合 Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u [Submit] [Go Ba ...
- 快速求排列组合 lucas定理
对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况. 就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 一般lucas定理的p ...
- 排列组合lucas模板
//codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元) #include <bits/stdc++.h> using nam ...
随机推荐
- 00_HTTP协议介绍
1. 什么是HTTP协议 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到 ...
- Cannot fetch index base URL https://pypi.python.org/pypi/ 解决方法
vi /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # ...
- html备忘录
上传文件 <form action="/ajax/" method="post" enctype="multipart/form-data&qu ...
- Easier Done Than Said?(应用到的知识)
memset(b,0,sizeof(b)) 对于大块儿内存的分配,例如int arr[100];定义了数组arr,包含100个元素,如果你写成int arr[100]=0;想将数组全部内容初始化为0, ...
- PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)
PAT (Basic Level) Practise (中文)-1025. 反转链表 (25) http://www.patest.cn/contests/pat-b-practise/1025 ...
- bootstrap历练实例: 基本胶囊式的导航菜单
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- Bootstrap历练实例:点击激活的按钮
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...
- shell脚本,如何写进度条。
[root@localhost ~]# cat jindutiao.sh #!/bin/bash #进度条 n=$((/)) N=$((/)) ` do sleep 0.01 [ $(($i%$n)) ...
- sed快速学习
- leepcode作业解析 - 5-20
22.缺失数字 给定一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数. 示例 1: 输入: [3,0,1] 输出: 2 示例 2: 输入: ...