ABC156D
[题目链接]https://atcoder.jp/contests/abc156/tasks/abc156_d
简单数论问题,题意就是有n个数,不能组成a与b个数,问有多少种组合方式
那就是C(n,1)+C(n,2)+....+C(n,n)-C(n,a)-C(n,b)
和式部分为2^n-1
由于a,b的范围在2e5,直接运用逆元+原始定义求两个组合数就行了
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;
const LL MOD = 1e9+7;
void ex_gcd(LL a, LL b, LL& x, LL& y) {
if(!b) {
x = 1, y = 0;
} else {
ex_gcd(b, a%b, y, x);
y -= x * (a / b);
}
}
LL inv(LL t, LL p) {
LL x, y, d;
ex_gcd(t, p, x, y);
return (x%p+p)%p;
}
LL quick_pow(LL a, LL b, LL p) {
LL ret = 1;
while(b) {
if(b & 1) ret = (ret * a) % p;
a = (a * a) % p;
b >>= 1;
}
return ret;
}
void run_case() {
LL n, a, b;
cin >> n >> a >> b;
if(n <= 2) {
cout << "0";
return;
}
LL all = quick_pow(2, n, MOD) - 1;
LL fa = 1, fb = 1;
// get a! and b!
for(LL i = a; i >= 1; --i)
fa = (fa * i) % MOD;
for(LL i = b; i >= 1; --i)
fb = (fb * i) % MOD;
LL n1 = 1, n2 = 1;
// get n*(n-1)---*(n-a+1)
for(LL i = n; i >= n-a+1; --i)
n1 = (n1 * i) % MOD;
for(LL i = n; i >= n-b+1; --i)
n2 = (n2 * i) % MOD;
//get MOD inverse
LL invfa = inv(fa, MOD), invfb = inv(fb, MOD);
all = ((all - n1*invfa%MOD)+MOD)%MOD;
all = ((all - n2*invfb%MOD)+MOD)%MOD;
cout << all;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cout.flags(ios::fixed);cout.precision(10);
run_case();
cout.flush();
return 0;
}
ABC156D的更多相关文章
- AT5341 [ABC156D] Bouquet 题解
Content 有一个人有 \(n\) 种不同的话可供选择,TA 可以选择至少一种花做花束,但是 TA 不喜欢花的种数为 \(a\) 或者 \(b\) 的花束.求选花的方案数对 \(10^9+7\) ...
随机推荐
- eclipse debug启动时tomcat报错
Class.getDeclaredConstructors0(boolean) line: not available [native method] tomcat debug启动突然启动不起来 停 ...
- ftp的相关配置
参考 https://www.cnblogs.com/hexige/p/7809481.html 访问参数
- anaconda+pytorch安装(无GPU版本)
anaconda+pytorch安装(无GPU版本) 待办 https://blog.csdn.net/nnUyi/article/details/78471326
- centos修改静态Ip地址
centos修改静态Ip地址 待办 昨天待办 https://blog.csdn.net/johnnycode/article/details/40624403 centos修改静态ip地址
- NOIP2016普及组解题报告
概述 \(NOIP2016\)普及组的前三题都比较简单,第四题也有很多的暴力分,相信参加了的各位\(OIer\)在\(2016\)年都取得了很好的成绩. 那么,我将会分析\(NOIP2016\)普及组 ...
- 测试理论 - Test Double
概述 简述 test double mock, fake 之类的东西 背景 最近在看 google 软件测试之道 妈的 13 年的老书了 书里有提到 mock, fake, stub 刚好, 我又不太 ...
- 【PAT甲级】1113 Integer Set Partition (25分)
题意: 输入一个正整数N(2<=N<=1e5),接着输入N个正整数,将这些数字划分为两个不相交的集合,使得他们的元素个数差绝对值最小且元素和差绝对值最大. AAAAAccepted cod ...
- selenium的显示等待、隐式等待
转载:https://www.cnblogs.com/mabingxue/p/10293296.html Selenium显示等待和隐式等待的区别1.selenium的显示等待原理:显示等待,就是明确 ...
- (c#)最小绝对差
题目 解
- django入门(一)
小白一枚,老是感觉自己学了点什么东西马上就忘了,所以打算写点下来,以后可以看看,也希望能给以后点进来的人有一些帮助 本文是django的入门,现在在学,有错误之处还希望能包涵和指出,谢谢! 首先先下载 ...