codeforces900D Unusual Sequences
1 second
256 megabytes
standard input
standard output
Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such that gcd(a1, a2, ..., an) = x and . As this number could be large, print the answer modulo 109 + 7.
gcd here means the greatest common divisor.
The only line contains two positive integers x and y (1 ≤ x, y ≤ 109).
Print the number of such sequences modulo 109 + 7.
3 9
3
5 8
0
There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).
There are no suitable sequences in the second test.
题意:问能构造出多少个序列满足,序列中所有元素的gcd为x,序列中所有元素的和为y
题解:首先序列中每个数字都可以用x*k表示,所以y是x的倍数,先判定。
之后就是放球问题,j个球放到i个箱子里允许为空。但是我们还要减去gcd是2x,3x...的方案数,这些数字正好可以对x分解质因数,然后逐个求解并减去。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[10005],dp[10005],n,m,tot;
ll pow(ll mi)
{ll res=1;for(ll a=2;mi;mi>>=1){if(mi&1) res=res*a%1000000007;a=a*a%1000000007;}return res;
}
int main()
{scanf("%I64d%I64d",&n,&m);if(m%n) return puts("0"),0;for(ll i=1;i<=sqrt(m);i++)if(m%i==0){if(i%n==0) a[++tot]=i;if(i*i!=m&&m/i%n==0) a[++tot]=m/i;}sort(a+1,a+tot+1);for(int i=tot;i;i--){dp[i]=pow(m/a[i]-1);for(int j=i+1;j<=tot;j++)if(a[j]%a[i]==0)dp[i]=(dp[i]-dp[j]+1000000007)%1000000007;}printf("%I64d\n",dp[1]);
}
codeforces900D Unusual Sequences相关推荐
- codeforces 900D. Unusual Sequences(莫比乌斯反演)
900D. Unusual Sequences(莫比乌斯反演) 题目链接:传送门 题意: 给出 xxx 和 yyy ,求序列形如 a1,a2..ana_1,a_2..a_na1,a2..an 满 ...
- D. Unusual Sequences (数论,质因子分解,dp)
D. Unusual Sequences time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 900D Unusual Sequences:记忆化搜索
题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...
- Codeforces Round #450 (Div. 2)D. Unusual Sequences[数论][组合数学][dp II]
题目:http://codeforces.com/contest/900/problem/D 题意:找到加和为m的且gcd为n的数列种类数 分析:可以转化为求gcd为1的加和为m/n的种类数,假设有m ...
- Unusual Sequences
题意: 求解合为 y 的总体 gcd 为 x 的正整数非空序列个数. 解法: 特判一下后,原问题等价于合为 s = y/x 的整体gcd为1的正整数序列个数. 1.$ans = \sum_{\sum{ ...
- D. Unusual Sequences
题解: 看到和式的时候就想到了插板法,然后我们需要剔除因子为gcd的倍数的情况,就比如我们在隔板(3,3,3,3)的时候算方案为232^323已经把(6,6)这种情况算了,但是这个是不满足的.所以我们 ...
- Unusual Sequences (隔板法+dp)
隔板法:参考 题意: 给你一个sum一个gcd,寻找数列满足a1+...+an==sum && gcd(a1,...,an) 的种类 题解: 1.如果sum%gcd!=0 输出0 2. ...
- 解题报告(十八)数论题目泛做(Codeforces 难度:2000 ~ 3000 + )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...
- Unusual Competitions
Unusual Competitions A bracketed sequence is called correct (regular) if by inserting "+" ...
最新文章
- 信息系统项目管理师:第4章:项目整体管理与变更管理(2)
- Python 绘制出酷炫的三维图
- 胡凌:隐私的终结——大数据时代的个体生活危机
- cmd命令操作Oracle数据库
- 关于linux系统中无法识别某一命令问题的解决方案
- Springboot 通过Ftp协议下载文件,并在Vue平台上显示其内容
- IT巨头埃森哲遭 LockBit 勒索攻击,黑客威胁泄露数据
- win11网络怎么优化 Windows11优化网速的步骤教程
- 由一个bug引发的SQLite缓存一致性探索
- 计算机应用职业生涯规划,计算机职业生涯规划书范文
- 突然间的一个阿里电话面试
- 《C》C语言实现DCT算法
- 【Qt+FFmpeg】给视频添加时间水印
- 如何编写测试用例及用例的意义
- Moffitt研究人员确定了为什么CAR T治疗可能对某些淋巴瘤患者无效
- 【JTeam Champion NFT】一张nft头像价值千万,能抵一套房,nft是数字艺术还是金融泡沫?
- 【voice-ui】代码用例展示并改主题配色,添加一键复制功能
- shp矢量数据打包压缩
- android 选择银行类型,vue2.0实现银行卡类型种类的选择
- 珍惜友谊远离匿名应用且行且珍惜