题目链接:

http://codeforces.com/contest/900/problem/D

题意:

给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数:

\(a_1, a_2, ..., a_n (1 ≤ a_i)\)。

$ 1.$ $gcd(a_1, a_2, ..., a_n) = x $

$ 2.$ \(\sum_{i=1}^{n}a_i = y\)

题解:

可以发现,当\(y\%x!=0\)时,满足条件的序列不存在。让\(f(t)\)表示满足序列和为的 \(t\),且\(gcd\) 为 \(1\) 的序列的个数。那么答案就是 \(f(\frac{y}{x})\)。

显然,用隔板法可以证明,把一个数 \(x\) 分解成可以由几个数组成的序列有\(2^{x-1}\)个,假设\(k=\frac{y}{x}\),把其中是质数的情况保留,把非质数的情况减去就可以了,这里用记忆化,容斥一下就可以得到答案了。

代码:

#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;
#define ll long long std::map<int, int> mp;
ll qpower(ll a,ll b,ll mod)
{
ll ans = 1;
while(b>0)
{
if(b&1) ans=(ans*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ans;
}
ll solve(int x)
{
if(x==1)return 1;
if (mp.count(x)) {
return mp[x];
}
mp[x] = qpower(2,x-1,mod);
for(int i=2;i*i<=x;i++) {
if(x%i==0){
mp[x] = (mp[x] - solve(x/i) + mod) % mod;
if(i!=x/i){
mp[x] = (mp[x] - solve(i) + mod) % mod;
}
}
}
mp[x] = (mp[x] - solve(1) + mod) % mod;
return mp[x];
}
int x,y;
int main(int argc, char const *argv[]) {
std::cin >> x >> y;
if(y%x!=0){
std::cout << "0" << '\n';
return 0;
}
std::cout << solve(y/x) << '\n';
return 0;
}

Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)的更多相关文章

  1. Codeforces Round #450 (Div. 2)

    Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...

  2. 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...

  3. Codeforces Round #450 (Div. 2) ABCD

    这次还是能看的0 0,没出现一题掉分情况. QAQ前两次掉分还被hack了0 0,两行清泪. A. Find Extra One   You have n distinct points on a p ...

  4. Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    B. Making Sequences is Fun time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  5. Codeforces Round #162 (Div. 1) B. Good Sequences (dp+分解素数)

    题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二 ...

  6. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  7. Codeforces Round #450 (Div. 2) C. Remove Extra One

    题目链接 题意:让你去掉一个数,使得剩下的数的record最多,当1≤j<i的aj<ai1 \leq j< i的a_j<a_i1≤j<i的aj​<ai​时aia_i ...

  8. Codeforces Round #450 (Div. 2) C. Remove Extra One【*模拟链表/一个数比前面所有数大就是个record。删掉一个数,让record的个数尽量多。】

    C. Remove Extra One time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #450 (Div. 2) B. Position in Fraction【数论/循环节/给定分子m 分母n和一个数c,找出c在m/n的循环节第几个位置出现,没出现过输出-1】

    B. Position in Fraction time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. hzwer 模拟题 祖孙询问

    祖孙询问 题目描述 已知一棵n个节点的有根树.有m个询问.每个询问给出了一对节点的编号x和y,询问x与y的祖孙关系. 输入输出格式 输入格式: 输入第一行包括一个整数n表示节点个数. 接下来n行每行一 ...

  2. 1.6 INSERT语句

    1.6 INSERT语句正在更新内容,请稍后

  3. 解决wget下载文件名乱码的一些方法

    在下载用apache或者nginx做的索引目录时,遇到文件名乱码问题.搜索了不少资料,尝试了好几种方案,大家可以结合使用. 一般情况下加上–restrict-file-names=nocontrol参 ...

  4. JeeSite信息化快速开发平台

     平台简介 JeeSite是基于多个优秀的开源项目,高度整合封装而成的高效,高性能,强安全性的开源Java EE快速开发平台. JeeSite是您快速完成项目的最佳基础平台解决方案,JeeSite是您 ...

  5. Linux 设置文件默认打开方式

    比如说我安装了一个绿色版的sublime(.tar解压出来的不是.deb) 但是现在我右键不能打开,不能添加为默认打开方式...这个时候就比较尴尬了... 我总不能每次都cd到安装目录下然后termi ...

  6. java高质量缩放图片

    可按照比例缩放,也可以指定宽高 import com.sun.image.codec.jpeg.JPEGImageEncoder; import com.sun.image.codec.jpeg.JP ...

  7. 洛谷——P2590 [ZJOI2008]树的统计

    https://www.luogu.org/problem/show?pid=2590#sub 题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这 ...

  8. 洛谷 P1757 通天之分组背包

    P1757 通天之分组背包 题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品 ...

  9. 洛谷 P1850 换教室

    P1850 换教室 题目描述 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程. 在可以选择的课程中,有 2n2n 节课程安排在 nn 个时间段上.在第 ii(1 \leq ...

  10. bootstrap之Orientation

    Orientation 调整屏幕方向的操作. package io.appium.android.bootstrap.handler; import android.os.RemoteExceptio ...