CodeForces - 900D: Unusual Sequences (容斥&莫比乌斯&组合数学)
Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such that gcd(a1, a2, ..., an) = x and . As this number could be large, print the answer modulo 109 + 7.
gcd here means the greatest common divisor.
Input
The only line contains two positive integers x and y (1 ≤ x, y ≤ 109).
Output
Print the number of such sequences modulo 109 + 7.
Examples
3 9
3
5 8
0
Note
There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).
There are no suitable sequences in the second test.
题意:N个未知数,他们的GCD是X,和是Y,问方案数。
思路:显然我们枚举GCD=x,然后就是(Y/X)/x-1个隔板,2^隔板。前面加莫比乌斯系数mu[x/X]即可。
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int Mod=1e9+;
int p[],cnt,ans,X,Y;
int qpow(int a,int x){
int res=; while(x){
if(x&) res=(ll)res*a%Mod;
a=(ll)a*a%Mod; x>>=;
}return res;
}
void dfs(int pos,int s,int opt)
{
if(pos>cnt) { ans=((ans+opt*qpow(,Y/s-))%Mod+Mod)%Mod; return ;}
dfs(pos+,s,opt); dfs(pos+,s*p[pos],-opt);
}
int main()
{
scanf("%d%d",&X,&Y);
if(Y%X!=) return puts(""),;
Y/=X; int tp=Y;
for(int i=;i<=tp/i;i++){
if(tp%i==) {
p[++cnt]=i;
while(tp%i==) tp/=i;
}
}
if(tp>) p[++cnt]=tp;
dfs(,,);
printf("%d\n",ans);
return ;
}
CodeForces - 900D: Unusual Sequences (容斥&莫比乌斯&组合数学)的更多相关文章
- cf900D. Unusual Sequences(容斥 莫比乌斯反演)
题意 题目链接 Sol 首先若y % x不为0则答案为0 否则,问题可以转化为,有多少个数列满足和为y/x,且整个序列的gcd=1 考虑容斥,设\(g[i]\)表示满足和为\(i\)的序列的方案数,显 ...
- Codeforces 900D Unusual Sequences 容斥原理
题目链接:900D Unusual Sequences 题意: 给出两个数N,M.让你求数列(和为M,gcd为N)的个数. 题解: 首先,比较容易发现的是M%N如果不为零,那么一定不能构成这样的序列 ...
- 【CF900D】Unusual Sequences 容斥(莫比乌斯反演)
[CF900D]Unusual Sequences 题意:定义正整数序列$a_1,a_2...a_n$是合法的,当且仅当$gcd(a_1,a_2...a_n)=x$且$a_1+a_2+...+a_n= ...
- CodeForces 900D Unusual Sequences
题目链接: https://codeforces.com/contest/900/problem/D 题意 假设有distinct 正整数序列{a1,a2,,,an},满足gcd(a1, a2, .. ...
- Codeforces 900D Unusual Sequences:记忆化搜索
题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...
- 【BZOJ3294】放棋子(动态规划,容斥,组合数学)
[BZOJ3294]放棋子(动态规划,容斥,组合数学) 题面 BZOJ 洛谷 题解 如果某一行某一列被某一种颜色给占了,那么在考虑其他行的时候可以直接把这些行和这些列给丢掉. 那么我们就可以写出一个\ ...
- Codeforces 803F Coprime Subsequences (容斥)
Link:http://codeforces.com/contest/803/problem/F 题意:给n个数字,求有多少个GCD为1的子序列. 题解:容斥!比赛时能写出来真是炒鸡开森啊! num[ ...
- Codeforces 100548F - Color (组合数+容斥)
题目链接:http://codeforces.com/gym/100548/attachments 有n个物品 m种颜色,要求你只用k种颜色,且相邻物品的颜色不能相同,问你有多少种方案. 从m种颜色选 ...
- 【二分+容斥+莫比乌斯反演】BZOJ2440 完全平方数
Description 求第k个没有完全平方因子的数,k<=1e9. Solution 这其实就是要求第k个µ[i](莫比乌斯函数)不为0的数. 然而k太大数组开不下来是吧,于是这么处理. 二分 ...
随机推荐
- Django 进阶篇之 CSRF,COOIKE,SESSION
1.CSRF(Cross Site Request Forgery, 跨站域请求伪造) CSRF 背景与介绍 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网 ...
- 树莓派从 DHT11 温度湿度传感器读取数据
时序图参考厂家说明书:DHT11数字湿温度传感器的原理和应用范例 四个阵脚连接:VCC接3.3伏电源,Dout接GPIO口,我接的是物理12针脚,NC留空,GND接地. 波折1:电阻被错接进了VCC, ...
- Linux基础三---打包压缩&vim&系统的初始化和服务
一,常用命令——tar&vim 1. tar [参数] 文件名 [路径] 参数: -c :建立一个压缩文件的参数指令(create 的意思): -x :解开一个压缩文件的参数指令! ...
- Git常见命令整理
Git常见命令整理 + 注释 git init # 初始化本地git仓库(创建新仓库) git config --global user.name "xxx" # 配置用户名 gi ...
- 缩略图悬浮效果的jQuery焦点图
在线演示 本地下载
- PHP的异常处理、错误的抛出及错误回调函数
一.错误.异常和等级常量表 error:不能再编译期发现运行期的错误,不如试图echo输出一个未赋值的变量,这类问题往往导致程序或逻辑无法继续下去而需要中断. exception:程序执行过程中出现意 ...
- problem-1003(恢复一下)
问题: Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequenc ...
- hive -e 时转义需要再加一个\
hive窗口中使用转义字符: select split(concat_ws('|','123','456','789'),'\\|')from dual; 参考 http://jingyan.baid ...
- 8.14比赛j题 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87813#overview
就我个人来说我觉得这道题其实不用写题解,只是因为做的时候错了一次,如果不是队友细心,我根本会错下去,所以我感觉自己必须强大#include<stdio.h> #include<str ...
- mysql删除重复记录
Solution 1: Add Unique Index on your table: ALTER IGNORE TABLE `TableA` ADD UNIQUE INDEX (`member_id ...