Codeforces Round 450 D 隔板法+容斥
题意:
Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such that gcd(a1, a2, ..., an) = xand . As this number could be large, print the answer modulo 109 + 7.
解法:
变成1+1+...+1=y/x ,用隔板法就知道有2^(y/x-1)个解
但是考虑到gcd不是1的情况。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int mod=1e9+;
ll quick_pow(ll a, ll b)
{
ll ans=;
while(b)
{
if(b&)
ans=ans*a%mod;//ans*a%mod;
a=a*a%mod;//a=a*a%mod;
b>>=;
}
return ans;
} vector<int> v;
ll ans=;
void dfs(int tot, int s, int len, int f){ if(tot==v.size()){
ans+=quick_pow(, len/s-)*f;
ans=(ans+mod)%mod;
return ;
} dfs(tot+, s*v[tot], len, -f);
dfs(tot+, s, len, f);
} int main(){ int x, y;
scanf("%d%d", &x, &y);
if(y%x==){
int len=y/x;
for(int i= ;i*i<=len; i++){
if(len%i==){
v.push_back(i);
while(len%i==){
len/=i;
}
}
}
if(len!=){
v.push_back(len);
}
//容斥
dfs(, , y/x, );
printf("%lld\n", ans);
}
else{
printf("0\n");
} return ;
}
Codeforces Round 450 D 隔板法+容斥的更多相关文章
- 牛客挑战赛 39 牛牛与序列 隔板法 容斥 dp
LINK:牛牛与序列 (牛客div1的E题怎么这么水... 还没D难. 定义一个序列合法 当且仅当存在一个位置i满足 $a_i>a_,a_j<a_$且对于所有的位置i,$1 \leq a_ ...
- Codeforces Round #450 (Div. 2)
Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...
- Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)
题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...
- Codeforces Round #450 (Div. 2) ABCD
这次还是能看的0 0,没出现一题掉分情况. QAQ前两次掉分还被hack了0 0,两行清泪. A. Find Extra One You have n distinct points on a p ...
- Codeforces 1553I - Stairs(分治 NTT+容斥)
Codeforces 题面传送门 & 洛谷题面传送门 u1s1 感觉这道题放到 D1+D2 里作为 5250 分的 I 有点偏简单了吧 首先一件非常显然的事情是,如果我们已知了排列对应的阶梯序 ...
- codeforces B. Friends and Presents(二分+容斥)
题意:从1....v这些数中找到c1个数不能被x整除,c2个数不能被y整除! 并且这c1个数和这c2个数没有相同的!给定c1, c2, x, y, 求最小的v的值! 思路: 二分+容斥,二分找到v的值 ...
- Codeforces 439E Devu and Birthday Celebration 容斥
Devu and Birthday Celebration 我们发现不合法的整除因子在 m 的因子里面, 然后枚举m的因子暴力容斥, 或者用莫比乌斯系数容斥. #include<bits/std ...
- Codeforces.997C.Sky Full of Stars(容斥 计数)
题目链接 那场完整的Div2(Div1 ABC)在这儿.. \(Description\) 给定\(n(n\leq 10^6)\),用三种颜色染有\(n\times n\)个格子的矩形,求至少有一行或 ...
- Codeforces 920G List Of Integers 二分 + 容斥
题目链接 题意 给定 \(x,p,k\),求大于 \(x\) 的第 \(k\) 个与 \(p\) 互质的数. 思路 参考 蒟蒻JHY. 二分答案 \(y\),再去 \(check\) 在 \([x,y ...
随机推荐
- 英语学习app——Alpha发布1
英语学习app--Alpha发布1 这个作业属这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/ ...
- 异想家Golang学习笔记
1. 简介 官网:https://golang.google.cn/ 2. 编译器.工具链 编译 go build .\demo.go 编译和执行指令合二为一 go run demo.go 3. 注释 ...
- JDK源码之String类解析
一 概述 String由final修饰,是不可变类,即String对象也是不可变对象.这意味着当修改一个String对象的内容时,JVM不会改变原来的对象,而是生成一个新的String对象 主要考虑以 ...
- 什么是 Trait
Trait 是从 PHP 5.4 加入的一种细粒度代码复用的语法.以下是官方手册对 Trait 的描述: Trait 是为类似 PHP 的单继承语言而准备的一种代码复用机制.Trait 为了减少单继承 ...
- 死磕mysql(4)
想把论坛和博客上所有关于mysql的都看一遍,死磕到底 看到关于数据库快照的东西.......不懂,百度......然后就跑题了,看到了表锁这种东西unlock tables; 用来锁定表..... ...
- qt QTreeWidget使用
itemwidget.h #ifndef ITEMWIDGET_H #define ITEMWIDGET_H #include <QtWidgets/QWidget> #include & ...
- 一些可以查询IP地理位置、身份证所在地、手机归属地的接口
查询IP http://ip.dnsexit.com/ 新浪的IP查询接口: 新浪的:http://counter.sina.com.cn/ip?ip=IP地址 返回Js数据,感觉不是很精确,可以把问 ...
- 《Android Studio实战 快速、高效地构建Android应用》--四、Git入门
Git版本控制系统(VCS)是分布式的,仓库的每一个副本均包含项目的完整历史 安装Git 下载 下载地址:http://git-scm.com/downloads 选择适合自己操作系统的来下载 如果下 ...
- android studio sqlite实际应用中存在的问题
原项目已上传到github long f = dbdatabase.update("user", values, "id=?", new String[]{St ...
- 设计模式——Adapter Pattern 适配器模式
我第一次接触设计模式,选取了四大类型里面的结构型,这类型的特点是关注类&对象之间的组合(使用继承),我从中选取适配器模式来具体学习. 一.适配器模式(Adapter Pattern)定义: 适 ...