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 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); 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 < ) 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 < || n < m) return ;
return 1LL * F[n] * Finv[m] % mod * Finv[n - m] % mod;
} inline int calc(int n, int m) {
if(m < n) return ;
return C(m - , n - );
} int main() {
inv[] = F[] = Finv[] = , miu[] = ;
for(int i = ; i < N; i++)
for(int j = i + i; j < N; j += i)
miu[j] -= miu[i];
for(int i = ; i < N; i++) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
for(int i = ; i < N; i++) F[i] = 1LL * F[i - ] * i % mod;
for(int i = ; i < N; i++) Finv[i] = 1LL * Finv[i - ] * inv[i] % mod;
for(int i = ; 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 = ;
for(int i = ; 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 ;
} /*
*/

Codeforces 439E Devu and Birthday Celebration 容斥的更多相关文章

  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 ...

  2. AcWing 214. Devu和鲜花 (容斥)打卡

    Devu有N个盒子,第i个盒子中有AiAi枝花. 同一个盒子内的花颜色相同,不同盒子内的花颜色不同. Devu要从这些盒子中选出M枝花组成一束,求共有多少种方案. 若两束花每种颜色的花的数量都相同,则 ...

  3. Codeforces 1553I - Stairs(分治 NTT+容斥)

    Codeforces 题面传送门 & 洛谷题面传送门 u1s1 感觉这道题放到 D1+D2 里作为 5250 分的 I 有点偏简单了吧 首先一件非常显然的事情是,如果我们已知了排列对应的阶梯序 ...

  4. codeforces B. Friends and Presents(二分+容斥)

    题意:从1....v这些数中找到c1个数不能被x整除,c2个数不能被y整除! 并且这c1个数和这c2个数没有相同的!给定c1, c2, x, y, 求最小的v的值! 思路: 二分+容斥,二分找到v的值 ...

  5. Codeforces.997C.Sky Full of Stars(容斥 计数)

    题目链接 那场完整的Div2(Div1 ABC)在这儿.. \(Description\) 给定\(n(n\leq 10^6)\),用三种颜色染有\(n\times n\)个格子的矩形,求至少有一行或 ...

  6. Codeforces 920G List Of Integers 二分 + 容斥

    题目链接 题意 给定 \(x,p,k\),求大于 \(x\) 的第 \(k\) 个与 \(p\) 互质的数. 思路 参考 蒟蒻JHY. 二分答案 \(y\),再去 \(check\) 在 \([x,y ...

  7. Codeforces 548E(莫反、容斥)

    转化为质数域上的操作,如果用莫反的话,记录因数的cnt. 其实莫反的推式子最后和容斥做法殊途同归了,容斥的系数就是莫比乌斯函数. const int maxn = 2e5 + 5, maxa = 5e ...

  8. CF451E Devu and Flowers (组合数学+容斥)

    题目大意:给你$n$个箱子,每个箱子里有$a_{i}$个花,你最多取$s$个花,求所有取花的方案,$n<=20$,$s<=1e14$,$a_{i}<=1e12$ 容斥入门题目 把取花 ...

  9. Codeforces Round 450 D 隔板法+容斥

    题意: Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers ...

随机推荐

  1. 三、Dockerfile的说明和编写

    一.docker hub的使用和说明: 我们要去找镜像,一般都会 https://hub.docker.com  的网站中去找,目前linux的容器,我们目前首选是alpine,因为容器非常小,可以满 ...

  2. 分布式协调服务Zookeeper扫盲篇

    分布式协调服务Zookeeper扫盲篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 身为运维工程师对kubernetes(k8s)可能比较熟,那么etcd(go语言实现)分布式协 ...

  3. 备忘录模式-Memento Pattern(Java实现)

    备忘录模式-Memento Pattern Memento备忘录设计模式是一个保存另外一个对象内部状态拷贝的对象,这样以后就可以将该对象恢复到以前保存的状态. 本文中的场景: 有一款游戏可以随时存档, ...

  4. 080、Weave Scope 容器地图(2019-04-28 周日)

    参考https://www.cnblogs.com/CloudMan6/p/7655294.html   Weave Scope 的最大特点是会自动生成一张 Docker 容器地图,让我们能够直接的理 ...

  5. css/css3 未知元素宽高,垂直居中和水平居中

    未知元素的宽高情况下  垂直居中和水平居中 第一种 flex盒布局 (推荐) /*弹性盒模型*/ /*主轴居中对齐*/ /*侧轴居中对齐*/ .ele{ display:flex; justify-c ...

  6. list转换string

    方法1 "".join 若list中为字符型 str = "".join(list) >>> L=['a','b','c'] >> ...

  7. Python 高级特性之:生成器(generator)和迭代器(Iterator)

    前言: 之前学习Python自动化,接触了不少python的学习,对生成器印象尤其深,网上也看了很多介绍,下面主要是这些概念的个人学习整理(如侵删). 正文: 如要创建一个非常大的列表,受到内存限制, ...

  8. Python:正则表达式(二):如何使用re.search()返回的匹配对象中的具体内容呢??

    在上一篇中讲述了re.seach()会返回一个对象格式的数据,如下:<_sre.SRE_Match object; span=(16, 24), match='${phone}'> 那么问 ...

  9. python数字常量

    数学常量 pi 数学常量 pi(圆周率,一般以π来表示) e 数学常量 e,e即自然常数(自然常数).

  10. L2-013 红色警报 (25 分) (并查集)

    链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805063963230208 题目: 战争中保持各个城市间的连通性非 ...