Codeforces 439E Devu and Birthday Celebration 容斥
Devu and Birthday Celebration
我们发现不合法的整除因子在 m 的因子里面, 然后枚举m的因子暴力容斥, 或者用莫比乌斯系数容斥。
#include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ALL(x) (x).begin(), (x).end() #define fio ios::sync_with_stdio(false); cin.tie(0);using namespace std;const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1);template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;} template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;} template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;} template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}int miu[N]; vector<int> fac[N]; int cnt[N], n, m;int F[N], Finv[N], inv[N]; int C(int n, int m) {if(n < 0 || n < m) return 0;return 1LL * F[n] * Finv[m] % mod * Finv[n - m] % mod; }inline int calc(int n, int m) {if(m < n) return 0;return C(m - 1, n - 1); }int main() {inv[1] = F[0] = Finv[0] = 1, miu[1] = 1;for(int i = 1; i < N; i++)for(int j = i + i; j < N; j += i)miu[j] -= miu[i];for(int i = 2; i < N; i++) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;for(int i = 1; i < N; i++) F[i] = 1LL * F[i - 1] * i % mod;for(int i = 1; i < N; i++) Finv[i] = 1LL * Finv[i - 1] * inv[i] % mod;for(int i = 1; i < N; i++)for(int j = i; j < N; j += i)fac[j].push_back(i);int T; scanf("%d", &T);while(T--) {scanf("%d%d", &m, &n);int ans = 0;for(int i = 0; i < SZ(fac[m]); i++)ans = (ans + 1LL * miu[fac[m][i]] * calc(n, m / fac[m][i]) % mod + mod) % mod;printf("%d\n", ans);}return 0; }/* */
转载于:https://www.cnblogs.com/CJLHY/p/10750245.html
Codeforces 439E Devu and Birthday Celebration 容斥相关推荐
- [CodeForces 439E] Devu and Birthday Celebration(莫比乌斯反演) | 错题本
文章目录 题目 分析 代码 题目 [CodeForces 439E] Devu and Birthday Celebration 分析 莫比乌斯函数比较重要的性质: μ ∗ 1 = ε \mu * 1 ...
- CF(439E - Devu and Birthday Celebration)莫比乌斯容斥
题意:将n个糖果插入f-1个挡板分成f分(a1,a2,a3...af). 问有多少种分法能够使得gcd(a1,a2,a3...af)=1; 解法.莫比乌斯容斥,首先按1为单位分,这时候有C(n-1,f ...
- CodeForces - 1425D Danger of Mad Snakes(容斥+组合数学)
题目链接:点击查看 题目大意:初始时有一个二维平面, 平面上给出 n 条蛇,现在可以选择 m 条不同的蛇进行捕杀,当选择了某条蛇,其所在的坐标可以覆盖到的半径为 r 的范围内的蛇都会被捕杀,更确切的说 ...
- codeforces B. Friends and Presents(二分+容斥)
题意:从1....v这些数中找到c1个数不能被x整除,c2个数不能被y整除! 并且这c1个数和这c2个数没有相同的!给定c1, c2, x, y, 求最小的v的值! 思路: 二分+容斥,二分找到v的值 ...
- CodeForces 997C-Sky Full of Stars〖容斥定理+组合计数〗
网页链接:传送门 C. Sky Full of Stars time limit per test : 4 seconds memory limit per test : 256 megabytes ...
- Codeforces 100548F - Color (组合数+容斥)
题目链接:http://codeforces.com/gym/100548/attachments 有n个物品 m种颜色,要求你只用k种颜色,且相邻物品的颜色不能相同,问你有多少种方案. 从m种颜色选 ...
- CodeForces - 1486F Pairs of Paths(树上计数+容斥)
题目链接:点击查看 题目大意:给出一棵 nnn 个点的树,再给出 mmm 条路径,现在问有多少个路径对 (x,y)(x,y)(x,y),满足第 xxx 条路径和第 yyy 条路径有且仅有一个交点 题目 ...
- Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...
- Codeforces Round #257 (Div. 1) D. Jzzhu and Numbers 高维前缀和 + 容斥
传送门 文章目录 题意: 思路: 题意: 思路: 完全想不到容斥啊,看了半天也没看懂渍渍渍. 定义f[i]f[i]f[i]表示iii的超集个数,那么选择的方案就是2f[i]−12^{f[i]}-12f ...
最新文章
- 摩尔线程推出首款数据中心级全栈功能GPU:MTT S2000
- Python 闭包相关之late binding机制
- PIX515防火墙配置策略实例
- php 剩余空间,PHP内核探索:内存的申请与销毁
- Linux数据库1366错误,ERROR 1366 (HY000): Incorrect string value:’XXX’ for column 'XXX at row 1解决...
- MongoDB快速入门(五)- Where子句
- 【PostgreSQL-9.6.3】表空间
- php之通过curl模仿表单提交(get,post)抓取其他页面的内容
- 电子元器件自动测试系统
- stc15f2k60s2单片机开发环境构建
- 支付宝小程序 alipays协议链接跳转
- Mybatis(狂神老师上课笔记)
- 触目惊心的互联网流量劫持
- 如何培训新进的软件测试人员
- 隐形数字水印_Android 实现图片水印与隐形数字水印
- Phaser3 + MatterJs 实现伪3D推金币
- 数学建模之matlab软件学习06——专题六 数值微积分与方程求解
- 给swagger的接口添加描述
- 当下最流行的10大H5前端框架
- 欢迎中文社区新版主@张特特