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 ...
随机推荐
- Spring-事务(1)
一,注解的方式实现事务 1.Dao层 package com.atguigu.spring.tx; public interface BookShopDao { //根据书号获取书的单价 public ...
- 超越队西柚考勤系统——beta冲刺1
这个作业属于哪个课程 http://edu.cnblogs.com/campus/xnsy/GeographicInformationScience 这个作业的要求在哪里 https://www.cn ...
- webapi的cors配置
NuGet搜索 cors,安装如图显示的: 一.全局配置 在App_Start文件夹的WebApiConfig.cs中加入代码 EnableCorsAttribute cors = new Enabl ...
- orm 锁 和 事务
一 锁 锁的语句 select_for_update() 原生sql语句select * from t1 for update django 语句models.T1.objects.select_fo ...
- DNS隧道基础
DNS协议是一种请求/应答协议,也是一种可用于应用层的隧道技术.虽然激增的DNS流量可能会被发现,但基于传统socket隧道已经濒临淘汰鸡TCP.UDP通信大量被防御系统拦截的状况,DNS.ICMP. ...
- 在Centos7上安装Oracle
环境: 硬盘30G:2G RAM:Centos7:Oracle 11G: 1.创建组和用户 [zzd@localhost ~]$ su root #切换到root Password: [root@lo ...
- <状压DP>solution-POJ3311_Hie with the Pie
Hie with the Pie Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers ...
- python笔记15
今日内容 模块知识 内置模块 time datetime json 其他 内容回顾 & 作业题 重要知识点 构造字典和函数对应关系,避免重复的if else a=1 b=2 ==> a, ...
- FFMPEG学习----使用SDL播放PCM数据
参考雷神的代码: /** * 最简单的SDL2播放音频的例子(SDL2播放PCM) * Simplest Audio Play SDL2 (SDL2 play PCM) * * 本程序使用SDL2播放 ...
- selenium pyunit单元测试框架
selenium pyunit单元测试框架 #PyUnit框架 #coding = utf - 8 #将要被测试的类 class Widget: def __int__(self,size = (40 ...