BZOJ2982: combination Lucas模板
2982: combination
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 734 Solved: 437
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
5 1
5 2
7 3
4 2
Sample Output
10
35
6
HINT
Source
lucas模板题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <sstream>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
template<class T>
inline void swap(T &a, T &b)
{
T tmp = a;a = b;b = tmp;
}
inline void read(long long &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
}
const long long INF = 0x3f3f3f3f;
const long long MAXN = ;
const long long MOD = ; long long f[MOD + ], t, n, m;
long long pow(long long a, long long b)
{
long long r = , base = a % MOD;
for(;b;b >>= )
{
if(b & ) r *= base, r %= MOD;
base *= base, base %= MOD;
}
return r;
}
long long ni(long long x)
{
return pow(x, MOD - );
}
long long C(long long n, long long m)
{
if(n < m) return ;
int tmp = f[n] * ni(f[m]) % MOD , tmp2 = tmp * ni(f[n - m]) % MOD;
return tmp2;
}
long long lucas(long long n, long long m)
{
if(!m) return ;
else return C(n % MOD, m % MOD) * lucas(n / MOD, m / MOD) % MOD;
} int main()
{
read(t);f[] = ;
for(long long i = ;i <= MOD;++ i)
f[i] = f[i - ] * i % MOD;
for(long long i = ;i <= t;++ i)
{
read(n), read(m);
printf("%lld\n", lucas(n, m));
}
return ;
}
BZOJ2982
BZOJ2982: combination Lucas模板的更多相关文章
- bzoj2982: combination(lucas定理板子)
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 664 Solved: 397[Submit][Status][Di ...
- BZOJ2982: combination Lucas
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- bzoj 2982 combination——lucas模板
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 明明是lucas定理裸题…… 非常需要注意C( )里 if ( n<m ) r ...
- BZOJ 2982: combination Lucas模板题
Code: #include<bits/stdc++.h> #define ll long long #define maxn 1000003 using namespace std; c ...
- [BZOJ2982]combination Lucas定理
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2982 $C(N,M)\% P = C(N\% P,M\% P) * C(N/P,M/P)\ ...
- 【BZOJ2982】combination Lucas定理
[BZOJ2982]combination Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然, ...
- 【题解】 bzoj2982: combination (Lucas定理)
题面戳我 Solution 板子题 Code //It is coded by ning_mew on 7.25 #include<bits/stdc++.h> #define LL lo ...
- bzoj2982: combination(Lucas定理)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- 2018.09.14 bzoj2982: combination(Lucas定理)
传送门 貌似就是lucas的板子题啊. 练一练手感觉挺舒服的^_^ 代码: #include<bits/stdc++.h> #define mod 10007 #define ll lon ...
随机推荐
- HTML5印章绘制电子签章图片,中文英文椭圆章、中文英文椭圆印章
原文:HTML5印章绘制电子签章图片,中文英文椭圆章.中文英文椭圆印章 电子签章图片采集 印章图片的采集两种互补方式: 方式1:在线生成印章图片方式,但是这种方式有个弊端,对印章中公司名称字数有限制, ...
- CobaltStrike进阶篇-批量上线
前言 当获取一台目标服务器权限时,更多是想办法扩大战果,获取目标凭据并横向进行登陆是最快速的拿权方式.但目标所处环境是否可出网,如何利用CobalStrike进行批量上线,正是本文所要讲述的内容. 获 ...
- 模板——二分图匹配KM
具体方法就不介绍了,详见 https://blog.csdn.net/sixdaycoder/article/details/47720471 主要讲一些注意点: 1:不直接将未匹配的y减小是因为要保 ...
- 一行神奇的 javascript 代码
写本篇文章的缘由是之前群里@墨尘发了一段js代码,如下: (!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+[]]*~ ...
- PAT甲级——A1007 Maximum Subsequence Sum
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to ...
- Delphi的日志库
1. 安装 Log4D下载: 官网地址 LoggerPro下载 GitHub地址 特点: log4d简单易用.性能稳定 LoggerPro貌似功能很强大,只是没有详细的文档,懒得翻源码 安装步骤 Lo ...
- rsync命令集合
rsync -avz rsync://logs@211.151.78.206/www_logs/2014/03/27/* /mnt/hgfs/iautoslogs/
- Python学习day35-并发编程(1)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- 线性SVM分类器实战
1 概述 基础的理论知识参考线性SVM与Softmax分类器. 代码实现环境:python3 2 数据处理 2.1 加载数据集 将原始数据集放入"data/cifar10/"文件夹 ...
- Codeforces 442B. Andrey and Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...