题目链接: 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的更多相关文章

  1. Codeforces 900D Unusual Sequences 容斥原理

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

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

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

  3. CF 900D Unusual Sequences

    题目链接 \(Description\) 给定\(x,y\),求有多少个数列满足\(gcd(a_i)=x且\sum a_i=y\).答案对\(10^9+7\)取模. \(1≤x,y≤10^9\) \( ...

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

  5. CodeForces - 900D: Unusual Sequences (容斥&莫比乌斯&组合数学)

    Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such ...

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

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

  7. CodeForces 373B Making Sequences is Fun

    Making Sequences is Fun Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  8. codeforces B. Making Sequences is Fun 解题报告

    题目链接:http://codeforces.com/problemset/problem/373/B 题目意思:给出w,m和k,需要找出从m开始,可以有多少个连续的数(m+1,m+2,...)(在添 ...

  9. Codeforces 264B Good Sequences(DP+素数筛)

    题目链接:http://codeforces.com/problemset/problem/264/B 题目大意:给出n个单调递增的数,让你找出最长的好序列,好序列是一种单调递增的并且相邻元素的最大公 ...

随机推荐

  1. axublogcms1.1.0 Getshell

    axublogcms1.1.0 Getshell 代码执行漏洞 现在最新版是1.1.0   今天重新审计了下 axublogcms1.0.6 ,发现一处计较鸡肋的漏洞,因为并不是只有1.0.6版本存在 ...

  2. Prometheus 监控Haproxy

    Prometheus 监控Haproxy 普罗米修斯是一个完整的监控和趋势系统,包括基于时间序列数据的内置和主动刮削,存储,查询,绘图和警报,以下使用Prometheus+grafana对Haprox ...

  3. PHP URL安全的Base64位编码

    先将内容编码成Base64结果; 将结果中的加号”+”替换成中划线“-“; 将结果中的斜杠”/”替换成下划线”_”; 将结果中尾部的“=”号全部保留; 实现 编码 function urlsafe_b ...

  4. RN-入门基础

    Props State 一切界面变化,都是state变化 state修改必须通过setState方法 this.state.like=true 这样复制无效 setState是一个merge合并的操作 ...

  5. .net core下载文件

    上传的文件是在wwwroot下  通过保存的路径跟文件名称完成下载 public IActionResult DownloadFile() { var filePath = "/Upload ...

  6. Python基础之字符串拼接简单介绍

    字符串拼接: %s表示可以传任意类型的值,%d表示只能传数字 test = "my name is %s,age %d" %("xyp",19) print(t ...

  7. 7.3.5 Tomcat堆溢出分析(1)

    实战Java虚拟机:JVM故障诊断与性能优化>第7章分析Java堆,本章主要介绍了Java堆的分析方法.首先,介绍了几种常见的Java内存溢出现象及解决思路.其次,探讨了java.lang.St ...

  8. 小程序[publib]:1 request:fail ssl hand shake error 如果用的是阿里云和宝塔那么如下解决

    小程序[publib]:1 request:fail ssl hand shake error 如果用的是阿里云和宝塔那么如下解决 宝塔里面的站点SSL右侧的配置(PEM格式) 需要把 阿里云 下载的 ...

  9. SAML2.0 SP端处理

    sso response解析 import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security ...

  10. scala 读取保存文件 去除字符特殊

    /** * 读取文件 * @param filename * @return */ def readFormFile(filename: String) = { var ooop = "&q ...