题目链接:

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. MySQL事务(event scheduler)的学习【事务创建之后,没有运行的问题】

    [本篇文章主要解决的是,MySQL事务创建之后,没有运行的问题] 首先从这里开始:http://www.w3schools.in/mysql/event-schedule/,创建了基本的MySQL事务 ...

  2. PHP 使用Apache 中的ab 測试站点的压力性能

    打开Apacheserver的安装路径(我用的是 WampServer),在bin文件夹中有一个ab.exe的可运行程序,它就是要介绍的压力測试工具. watermark/2/text/aHR0cDo ...

  3. php将数组或字符串写入文件

    //将数组保存在文件里 function export_to_file($file, $variable) { $fopen = fopen($file, 'wb'); if (!$fopen) { ...

  4. oracle 数据库批处理文件

    文件夹结构 初始化脚本 |----orcl_sql |----init_user.sql |----tab_home.sql |----TAB_USER.sql |----init.bat init. ...

  5. 排序(1)---------选择排序(C语言实现)

    选择排序的基本思想: 选择排序(Selection sort)是一种简单直观的排序算法. 它的工作原理例如以下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素 ...

  6. webgoat 7.1 实战指南

    WSASP中文文档参考链接: http://www.owasp.org.cn/owasp-project/2017-owasp-top-10 OWASP Top 10 2017中文版V1.3http: ...

  7. ctags 寻找方法定义处

    ctags这个是vim的一个插件,它可以用来生成一个检索文件,里面保存有一些索引信息.例如,一些类跟方法.变量等的定义位置当我们对一个路径执行ctags -R的时候,就会自动生成一个ctags,然后我 ...

  8. 关于li的排列,我的面试题

    来到北京的第二周,收到了单位的面试,一面的时候面试官问了微信钱包里的那个快速入口的排列,我当时在面试官的引导下答的还可以,但是在实际中有很多的方法和各自不同的问题,我来总结下. 1.flex布局,其实 ...

  9. C#开发 —— 基础知识

    C# 用于开发可以运行在 .Net 平台上的应用程序,C# 本身只是一种语言,尽管它是用于生成面向 .Net 环境的代码,但它本身不是 .Net 的一部分 Console.WriteLine 命名空间 ...

  10. SQL insert 主键冲突

    待总结 https://blog.csdn.net/JavaCoder_juejue/article/details/82313891 https://blog.csdn.net/a772304419 ...