CodeForces 900D Unusual Sequences
题目链接: https://codeforces.com/contest/900/problem/D
题意
假设有distinct 正整数序列{a1,a2,,,an},满足gcd(a1, a2, ..., an) = x ,且 ∑ai = y,那么求满足条件的序列的数目。
老题,一直没AC,今天算是明白了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; const ll mod=(ll)1e9+;
ll qPow(ll a,ll b,ll m)
{
ll ret=1ll;
while(b){
if(b&) ret=(ret*a)%m;
a=a*a%m;
b>>=;
}
return ret;
} map<ll , ll> F;
ll getF(ll t){
if(F.count(t)){
return F[t];
}
ll ans=qPow(2ll,t-,mod);
for(ll i=2ll;i*i<=t;++i){
if(t%i) continue;
ll j=t/i;
if(i!=j) ans=ans-getF(i)+mod-getF(j)+mod;
else ans=ans-getF(i)+mod;
ans%=mod;
}
ans=(ans-F[]+mod)%mod;
F[t]=ans;
return F[t];
} int main(){
ios::sync_with_stdio(false);cin.tie();
ll XX,YY;
cin>>XX>>YY;
if(YY%XX){
cout<<<<endl;
}
else{
ll tot=YY/XX;
F[]=1ll;
cout<<getF(tot)<<endl;
}
return ;
}
CodeForces 900D Unusual Sequences的更多相关文章
- Codeforces 900D Unusual Sequences 容斥原理
题目链接:900D Unusual Sequences 题意: 给出两个数N,M.让你求数列(和为M,gcd为N)的个数. 题解: 首先,比较容易发现的是M%N如果不为零,那么一定不能构成这样的序列 ...
- Codeforces 900D Unusual Sequences:记忆化搜索
题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...
- CF 900D Unusual Sequences
题目链接 \(Description\) 给定\(x,y\),求有多少个数列满足\(gcd(a_i)=x且\sum a_i=y\).答案对\(10^9+7\)取模. \(1≤x,y≤10^9\) \( ...
- 【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 (容斥&莫比乌斯&组合数学)
Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such ...
- Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)
题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...
- CodeForces 373B Making Sequences is Fun
Making Sequences is Fun Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- codeforces B. Making Sequences is Fun 解题报告
题目链接:http://codeforces.com/problemset/problem/373/B 题目意思:给出w,m和k,需要找出从m开始,可以有多少个连续的数(m+1,m+2,...)(在添 ...
- Codeforces 264B Good Sequences(DP+素数筛)
题目链接:http://codeforces.com/problemset/problem/264/B 题目大意:给出n个单调递增的数,让你找出最长的好序列,好序列是一种单调递增的并且相邻元素的最大公 ...
随机推荐
- linux下怎么清理缓存
free -m 命令可以查看内存使用情况 sysctl 命令可以临时改变某个系统参数 如:sysctl -w net.ipv4.ip_forward=1 是将forware参数临时改为1 当 ser ...
- WPF常用TriggerAction用法 (一)
Microsoft.Expression.Interactivity 常用TriggerAction-> CallMethodAction ChangePropertyAction Contro ...
- pycharm 激活码
http://www.cnblogs.com/itfat/p/9388829.html
- html client websocket
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- OSS RFC
This is a very late reply, but just want to share the process of setting up all associated RFCs with ...
- es6 和 python 语法比较
http://www.linchaoqun.com/html/cms/content.jsp?id=1509528630774 Python3笔记:Python与ECMAScript部分语法对比 ht ...
- (7/24) 插件配置之html文件的打包发布
从前面几节到现在,其实我们的项目结构是有问题的,因为我们直接把index.html文件放到了dist文件夹目录下.这肯定是不正确的,应该放到我们src目录下,然后打包到dist目录下,前面为了学习,才 ...
- gp工具的许可
还是要在代码里许可 static class Program { [STAThread] static void Main() { ESRI.ArcGIS.RuntimeManager.Bind(ES ...
- python-day6面向对象、类的继承
@面向对象三大特性:封装encapsulation.继承inheritance.多态(一个接口,多个实现)polymorphism. @面向对象介绍http://www.cnblogs.com/ale ...
- mysql创建用户并分配权限
添加新用户 允许本地 IP 访问 localhost, 127.0.0.1 create user 'test'@'localhost' identified by '123456'; 允许外网 IP ...