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个单调递增的数,让你找出最长的好序列,好序列是一种单调递增的并且相邻元素的最大公 ...
随机推荐
- Scrapy实战篇(九)之爬取链家网天津租房数据
以后有可能会在天津租房子,所以想将链家网上面天津的租房数据抓下来,以供分析使用. 思路: 1.以初始链接https://tj.lianjia.com/zufang/rt200600000001/?sh ...
- spark2.1源码分析2:从SparkPi分析一个job的执行
从SparkPi的一个行动操作入手,选择Run–Debug SparkPi进入调试: F8:Step Over F7:Step Into 右键Run to Cursor Ctrl+B 查看定义 导航– ...
- .net core2 单元测试
1.下载 https://marketplace.visualstudio.com/items?itemName=RandomEngy.UnitTestBoilerplateGenerator 2 ...
- 在WINDOWS服务器下设置MARIADB自动备份的方法
WINDOWS服务器下自动备份有三个步骤 1.首先新建一个.BAT文件里面输入 @echo offset "Ymd=%date:~,4%%date:~5,2%%date:~8,2%" ...
- golang 统计uint64 数字二进制存储中1的数量
package main import ( "fmt") // pc[i] is the population count of i.var pc [256]byte fun ...
- jQuery 正则数字验证、’Money验证、电话号码验证、身份证验证、邮箱验证、网址验证、敏感字符验证
jQuery只能输入数字 第一种写法: <input onkeyup="value=value.replace(/[^\d]/g,'')" /> 第二种写法: < ...
- 【Appium自学】Android studio安装与配置(转)
转自链接:https://www.cnblogs.com/xiadewang/p/7820377.html 1.首先下载Android studio安装包. 可以从http://www.android ...
- ajax的4个字母分别是什么意思
Asynchronous JavaScript and XML 的缩写,异步的JavaScript和XML.在不重新加载整个页面的情况下 ,AJAX 与服务器交换数据并更新部分网页.
- Delphi 窗口操作
unit UnitWinUtils; interface uses Windows; Type TDWA128=Array [..] of LongWord; TDWA256=Array [..] o ...
- 深入理解Java虚拟机之JVM垃圾回收随笔
1.对象已经死亡? 1.1引用计数法:给对象中添加一个引用计数器,每当有一个地方引用他时,计数器值就加1:当引用失效时,计数器值就减1:任何时刻计数器都为0的对象就是不可能再被使用 的.但是它很难解决 ...