题意:

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 隔板法+容斥的更多相关文章

  1. 牛客挑战赛 39 牛牛与序列 隔板法 容斥 dp

    LINK:牛牛与序列 (牛客div1的E题怎么这么水... 还没D难. 定义一个序列合法 当且仅当存在一个位置i满足 $a_i>a_,a_j<a_$且对于所有的位置i,$1 \leq a_ ...

  2. Codeforces Round #450 (Div. 2)

    Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...

  3. Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)

    题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...

  4. Codeforces Round #450 (Div. 2) ABCD

    这次还是能看的0 0,没出现一题掉分情况. QAQ前两次掉分还被hack了0 0,两行清泪. A. Find Extra One   You have n distinct points on a p ...

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

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

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

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

  7. Codeforces 439E Devu and Birthday Celebration 容斥

    Devu and Birthday Celebration 我们发现不合法的整除因子在 m 的因子里面, 然后枚举m的因子暴力容斥, 或者用莫比乌斯系数容斥. #include<bits/std ...

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

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

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

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

随机推荐

  1. Ubuntu16手动安装OpenStack

    记录大佬的博客全文转载于https://www.voidking.com/dev-ubuntu16-manual-openstack-env/ 前言 <Ubuntu16安装OpenStack&g ...

  2. VMware 虚拟机开机黑屏

    先记录一下害我差点点就又跑去重装了 好几天未打开vm 打开就黑屏 打开虚拟机就是黑屏没反应 找了很久(好像是wegame的原因,昨晚上好像是打开了wegame更新2k和lol) 1献上解决方案 管理员 ...

  3. 基于Flask框架搭建视频网站的学习日志(三)之原始web表单

    基于Flask框架搭建视频网站的学习日志(三)1.原始Web 表单 本节主要用于体验一下前端后端直接数据的交互,样例不是太完善,下一节会加入Flash处理,稍微完善一下页面 (备注:建议先阅读廖雪峰老 ...

  4. 解决linux安装软件:/lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录

    在linux系统中安装软件:/lib/ld-linux.so.2: bad ELF interpreter怎么解决 常用的安装因为系统软件位数问题,如:64位系统中安装了32位程序了, 是因为64位系 ...

  5. Ecplise中指定tomcat里Web项目发布文件

    有时候发布项目时,我们会看到Ecplise会自动把一些并不是我们想需要的文件也发布到服务器上,可以通过以下方式解决: Properties->Deployment Assembly

  6. Win10系统下如何将中文登录名改为英文登录名

    需求:本人每次在换完系统后是默认,图方便,登录名就直接是自己的名字,造成以后安装个别软件时会莫名其妙的出错. 解决办法: 1.在当前用户开始处-点击右键(Windows键+X)-注销 2.切换到Adm ...

  7. GDI+如何判断一个点是否在区域内

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms533826(v=vs.85).aspx The purpose of hit t ...

  8. WTL使用双缓冲避免重绘闪烁

    1.继承自CDoubleBufferImpl template <class T> class CDoubleBufferImpl { public: // Overrideables v ...

  9. PAT_B1002数字分类

    #include<stdio.h> #include<iostream> using namespace std; int main(){ ,a2=,a3=,a5=; ; ; ...

  10. Deep Learning for Chatbots(Introduction)

    聊天机器人又被称为会话系统,已经成为一个热门话题,许多公司都在这上面的投入巨大,包括微软,Facebook,苹果(Siri),Google,微信,Slack.许多创业公司尝试通过多种方式来改变与消费者 ...