Codeforces Round 729 (Div. 2)B. Plus and Multiply(构造、数学)
题面

链接
题意
给定\(n,a,b\)
可以进行的操作
- \(*a\)
- \(+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(构造、数学)的更多相关文章
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- 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 ...
- 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 ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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/ ...
- 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 ...
随机推荐
- 3.3 Windows驱动开发:内核MDL读写进程内存
MDL内存读写是一种通过创建MDL结构体来实现跨进程内存读写的方式.在Windows操作系统中,每个进程都有自己独立的虚拟地址空间,不同进程之间的内存空间是隔离的.因此,要在一个进程中读取或写入另一个 ...
- WinForm之ComboBox实现模糊查询
ComboBox实现模糊查询 第一步:在Form_Load事件中绑定数据源 第二步:写一个方法,返回一个List<string>类型的集合来存储控件中的Items 第三步:在Form_Lo ...
- 将Windows系统设置为NTP服务器
环境 Windows 10,本机IP地址为:192.168.6.133 步骤 一.编辑注册表 win+r快捷键打开运行窗口,输入regedit打开注册表编辑器,找到以下几项并修改其值: 1.将type ...
- P9549 「PHOI-1」路虽远 题解
题目链接:路虽远 带限制的 dijkstra,优先考虑有哪些限制条件,当做类似 dp 去写.闯黄灯次数有要求,限制速度的边数量有要求. 我们注意到,如果选择哪些边限速不易于基于贪心选择,可以考虑转换下 ...
- 基于客户真实使用场景的云剪辑Timeline问题解答与代码实操
本文为阿里云智能媒体服务IMS「云端智能剪辑」实践指南第6期,从客户真实实践场景出发,分享一些Timeline小技巧(AI_TTS.主轨道.素材对齐),助力客户降低开发时间与成本. 欧叔|作者 故事的 ...
- CH59X/CH58X/CH57X sleep模式下串口唤醒收发数据
整体程序逻辑: 下方的具体程序及使用是基于CH592进行的 SLEEP模式睡眠唤醒是由协议栈管理的,还在睡眠时,无法接收到数据. 已经通过使能HAL_SLEEP开启睡眠.如果需要在睡眠时实时接收串口传 ...
- JS leetcode 反转字符串 题解分析
壹 ❀ 引 今天做的一道题非常简单,原题来自leetcode第344题反转字符串,题目如下: 编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出. 不要给另外 ...
- mysql 8.0 配置文件my.cnf中文注解【转载】
########################################################################### ## my.cnf for MySQL 8.0. ...
- 【leetcode】如何实现 regex 正则表达式引擎
题目 给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符 '*' 匹配零个或多个前面的那一个元素 所谓匹配,是要涵盖 整个 字 ...
- 【Unity3D】地面网格特效
1 前言 本文实现了地面网格特效,包含以下两种模式: 实时模式:网格线宽度和间距随相机的高度实时变化: 分段模式:将相机高度分段,网格线宽度和间距在每段中对应一个值. 本文完整资源见→Unit ...