题面

链接

B. Plus and Multiply

题意

给定\(n,a,b\)

可以进行的操作

  1. \(*a\)
  2. \(+b\)

最开始的数是1

问能否经过上面的两种操作将1变为n

题解

这题的关键是能不能想出来这个集合里面的数的统一的表达形式

所有数都可以表示为

\(a^x+y * b\)

然后只要存在\(x\)和\(y\),使得\(a^x+y * b=n\)即可

对上式进行等价变换可以得到

\((n-a^x)\equiv0\quad (mod \quad b)\)

还有需要注意的是特判\(a=1\)的情况,因为\(a=1\)时会陷入死循环

代码

#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back using namespace std;
const int N=2e5+10;
int a[N];
void solve()
{
int n,a,b;
cin>>n>>a>>b;
if(a==1){
cout<<((n%b)==(1%b)?"YES":"NO")<<endl;
return;
}
for(int i=1;i<=n;i*=a){
if((n-i)%b==0){
cout<<"YES"<<endl;
return;
}
}
cout<<"NO"<<endl;
} signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}

总结

对数学推式子的能力还是太差,需要多练

Codeforces Round 729 (Div. 2)B. Plus and Multiply(构造、数学)的更多相关文章

  1. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  2. Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学

    D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...

  3. Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数

    D. Soldier and Number Game Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  4. Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题

    C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...

  5. Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学

    B. Chloe and the sequence 题目链接 http://codeforces.com/contest/743/problem/B 题面 Chloe, the same as Vla ...

  6. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

  7. Codeforces Round #342 (Div. 2) A - Guest From the Past 数学

    A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...

  8. Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  9. Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造

    B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  10. Codeforces Round #185 (Div. 2) C. The Closest Pair 构造

    C. The Closest Pair Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/p ...

随机推荐

  1. TienChin 运行 RuoYi-Vue3

    在前几篇文章当中,之前使用的是 Vue2,在某一天发现若依提供了 Vue3 的版本,所以这篇文章主要是运行起来,Vue2,迟早要被替代,所以这里采用最先进的 Vue3. 仓库地址:https://gi ...

  2. Jupyter Notebook 下 import 第三方库,显示 no module xxx 【本质是环境没有切换过来】

    1.最简单情况下 切换环境即可 首先激活环境: ​ activate env  # 激活你的环境名称 jupyter notebook ​ 之后去运行代码即可,如果还不行请看下面: 2.遇到Jupyt ...

  3. 2.基于Label studio的训练数据标注指南:(智能文档)文档抽取任务、PDF、表格、图片抽取标注等

    文档抽取任务Label Studio使用指南 1.基于Label studio的训练数据标注指南:信息抽取(实体关系抽取).文本分类等 2.基于Label studio的训练数据标注指南:(智能文档) ...

  4. C# 语言程序设计笔记

    C#是一种最新的.面向对象的编程语言.它使得程序员可以快速地编写各种基于Microsoft .NET平台的应用程序,Microsoft .NET提供了一系列的工具和服务来最大程度地开发利用计算与通讯领 ...

  5. Flink-SQL数据去重

    Flink去重语句 您可以通过多种方式实现去重需求,例如FIRST_VALUE.LAST_VALUE和DISTINCT等.本文为您介绍如何使用TopN方法实现去重,以及使用过程中的注意事项. 去重的方 ...

  6. [Java]BigDecimal与Double的区别和使用场景

    BigDecimal与Double的区别和使用场景 背景 在项目中发现开发小组成员在写程序时,对于Oracle数据类型为Number的字段(经纬度),实体映射类型有的人用Double有的人用BigDe ...

  7. RocketMQ—RocketMQ消费重试和死信消息

    RocketMQ-RocketMQ消费重试和死信消息 消费重试 生产者重试 设置重试的代码如下 // 失败的情况重发3次 producer.setRetryTimesWhenSendFailed(3) ...

  8. NC50390 布局 Layout

    题目链接 题目 题目描述 FJ有N头奶牛 \((2 \leq N \leq1000)\) ,编号为 \(1 \ldots N\) .奶牛们将按照编号顺序排成一列队伍(可能有多头奶牛在同一位置上).换句 ...

  9. Python中矩阵运算(基于numpy包)

    1 乘法 在数组中,a * a计算对应元素相乘(矩阵点乘):在矩阵中,A*A计算矩阵乘法 np.multiply()计算对应元素相乘(矩阵点乘) np.dot()计算矩阵乘法 import numpy ...

  10. 利用nssm将jar包安装为windows服务

    1.介绍 假设我们有一个spring boot程序打包成jar文件放到windows服务器运行,第一种方式jar -jar xx方式在cmd运行.这样有个缺点,被别人误关闭了咋办?服务器重启了咋办? ...