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. Windows系统CMD下常用命令

    命令    功能ASSOC    显示或修改文件扩展名关联.ATTRIB    显示或更改文件属性.BREAK    设置或清除扩展式 CTRL+C 检查.BCDEDIT    设置启动数据库中的属性 ...

  2. jvm 字节码执行 (一)方法调用

    “虚拟机”是一个相对于“物理机”的概念,这两种机器都有代码执行能力,其区别是物理机的执行引擎是直接建立在处理器.硬件.指令集和操作系统层面上,而虚拟机的执行引擎是 由自己实现的,因此可以自行制定指令集 ...

  3. Mysql查询库、表存储量(Size)

    Mysql查询库.表存储量(Size) 1.要查询表所占的容量,就是把表的数据和索引加起来就可以了. SELECT SUM(DATA_LENGTH) + SUM(INDEX_LENGTH) FROM ...

  4. python 单例实现

    class View: _instance = None def __new__(cls, *args, **kwargs): if cls._instance is None: cls._insta ...

  5. python开发基础之语法基础

    一.知识点 (一)python介绍 1.Python被设计成一种高可读性的语言,它大量地使用了英语单词作为关键字,不像其他语言使用标点符号构成复杂的语法结构. 2.Pyton是支持面向对象的,支持在对 ...

  6. 通过配置文件新建solr的core

    目录solr-7.5.0\server\solr 1.  新建文件夹 test-core 2. 在文件夹test-core下新建core.properties name=test-core confi ...

  7. 双目立体匹配——归一化互相关(NCC)

    归一化相关性,normalization cross-correlation,因此简称NCC,下文中笔者将用NCC来代替这冗长的名称. NCC,顾名思义,就是用于归一化待匹配目标之间的相关程度,注意这 ...

  8. jsonp和CORS跨域实现

    一.jsonp,使用jquery封装的$.ajax,返回数据类型要设置为jsonp 示例: $.ajax({ type: 'get', contentType: "application/j ...

  9. pycharm+selenium搭建环境

    1.在你的python安装目录D:\Python36\Scripts下执行pip install selenium 2.安装完成后最好直接打开python,在下面输入from selenium imp ...

  10. Shiro权限管理

    1.简介 Apache Shiro是Java的一个安全框架,对比Spring Security,没有Spring Security功能强大,但在实际工作时可能并不需要那么复杂,所以使用小而简单的Shi ...