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

Input
3 9
Output
3
Input
5 8
Output
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 (容斥&莫比乌斯&组合数学)的更多相关文章

  1. cf900D. Unusual Sequences(容斥 莫比乌斯反演)

    题意 题目链接 Sol 首先若y % x不为0则答案为0 否则,问题可以转化为,有多少个数列满足和为y/x,且整个序列的gcd=1 考虑容斥,设\(g[i]\)表示满足和为\(i\)的序列的方案数,显 ...

  2. Codeforces 900D Unusual Sequences 容斥原理

    题目链接:900D  Unusual Sequences 题意: 给出两个数N,M.让你求数列(和为M,gcd为N)的个数. 题解: 首先,比较容易发现的是M%N如果不为零,那么一定不能构成这样的序列 ...

  3. 【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= ...

  4. CodeForces 900D Unusual Sequences

    题目链接: https://codeforces.com/contest/900/problem/D 题意 假设有distinct 正整数序列{a1,a2,,,an},满足gcd(a1, a2, .. ...

  5. Codeforces 900D Unusual Sequences:记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...

  6. 【BZOJ3294】放棋子(动态规划,容斥,组合数学)

    [BZOJ3294]放棋子(动态规划,容斥,组合数学) 题面 BZOJ 洛谷 题解 如果某一行某一列被某一种颜色给占了,那么在考虑其他行的时候可以直接把这些行和这些列给丢掉. 那么我们就可以写出一个\ ...

  7. Codeforces 803F Coprime Subsequences (容斥)

    Link:http://codeforces.com/contest/803/problem/F 题意:给n个数字,求有多少个GCD为1的子序列. 题解:容斥!比赛时能写出来真是炒鸡开森啊! num[ ...

  8. Codeforces 100548F - Color (组合数+容斥)

    题目链接:http://codeforces.com/gym/100548/attachments 有n个物品 m种颜色,要求你只用k种颜色,且相邻物品的颜色不能相同,问你有多少种方案. 从m种颜色选 ...

  9. 【二分+容斥+莫比乌斯反演】BZOJ2440 完全平方数

    Description 求第k个没有完全平方因子的数,k<=1e9. Solution 这其实就是要求第k个µ[i](莫比乌斯函数)不为0的数. 然而k太大数组开不下来是吧,于是这么处理. 二分 ...

随机推荐

  1. HDF 文件数据的读取

    http://www.cams.cma.gov.cn/cams_973/cheres_docs/cheres_doc_sat.modis.1b.html一. HDF文件格式 1.概述 HDF 是美国国 ...

  2. (C#)ListView双击Item事件

    /// <summary> /// 双击选择播放列表项进行播放 /// </summary> /// <param name="sender"> ...

  3. python基础深入(元组、字符串、列表、字典)

    python基础深入(元组.字符串.列表.字典) 一.列表 1.追加 >>>list = [1,2,3,4] #用于在列表末尾添加新的对象,只能单个添加,该方法无返回值,但是会修改原 ...

  4. javascript;select动态添加和删除option

    <select id="sltCity"></select> //添加Option. var optionObj = new Option(text, va ...

  5. openGL学习进程(1)OpenGL的简介

        通过本节,我们来简要了解一下openGL.     (1)OpenGL概述: openGL(Open Graphics Library)是个专业的图形程序接口,定义了一个跨编程语言.跨平台的编 ...

  6. $《第一行代码:Android》读书笔记——第13章 Android高级技巧

    (一)全局获取Context 1.创建ApplicationUtil类继承自Application类: public class ApplicationUtil extends Application ...

  7. 【leetcode刷题笔记】Excel Sheet Column Number

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

  8. 关于pycharm中的requirements.txt文件

    作用:记录所有所依赖的第三方模块,方便迁移到不同的环境中后,防止缺少模块,或因为所依赖的第三方模块版本不同引起不必要的问题 生成命令:pip freeze > requirements.txt ...

  9. cocos2dx打飞机项目笔记七:各种回调:定时器schedule、普通回调callFunc、菜单回调menu_selector、事件回调event_selector

    各种回调函数的定义: typedef void (CCObject::*SEL_SCHEDULE)(float); typedef void (CCObject::*SEL_CallFunc)(); ...

  10. Android LCD(一):LCD基本原理【转】

    本文转载自:http://blog.csdn.net/longxiaowu/article/details/24787597 关键词:Android LCD TFT 液晶 偏光片 彩色滤光片  背光 ...