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 ...
随机推荐
- 21.6 Python 构建ARP中间人数据包
ARP中间人攻击(ARP spoofing)是一种利用本地网络的ARP协议漏洞进行欺骗的攻击方式,攻击者会向目标主机发送虚假ARP响应包,使得目标主机的ARP缓存中的IP地址和MAC地址映射关系被篡改 ...
- WebAssembly入门笔记[4]:利用Global传递全局变量
利用WebAssembly的导入导出功能可以灵活地实现宿主JavaScript程序与加载的单个wasm模块之间的交互,那么如何在宿主程序与多个wasm之间传递和共享数据呢?这就需要使用到Global这 ...
- centos离线安装mongodb-database-tools
mongodb-database-tools是MongoDB数据库工具的命令行的工具,用于工作与MongoDB部署.可以使用mongodump和mongoimport很方便的导入导出备份数据. 该数据 ...
- CF678F Lena and Queries题解
题目链接:CF 或者 洛谷 可以看到查询和插入就是李超线段树的基本操作,但在原有基础上多了一个删除操作,李超线段树不支持删除操作,但支持可撤销和可持久化,所以我们容易想到外层再套一个线段树分治即可.本 ...
- (C语言)我的第一个项目:命令行窗口下的学生成绩管理系统,及数据生成程序
学生成绩管理系统 页面效果如图: 代码如下: #include <stdio.h> #include <stdlib.h> #include <string.h> ...
- Hbase-执行hbase shell命令时提示:ERROR: KeeperErrorCode = NoNode for /hbase/master
1.问题描述 执行hbase shell命令时提示: ERROR: KeeperErrorCode = NoNode for /hbase/master 2.问题原因 这是与因为服务器重启后Hado ...
- ABC 310
E \(dp[i][j]\) 表示前 \(i\) 个里有多少个后缀答案为 \(j\). \(if (c[i] == '0') \{\) \(dp[i][0] = 1;\) \(dp[i][1] = d ...
- Argocd学习
argocd官网文档链接 ArgoCD官网文档 在K8S集群使用argocd命令将集群添加到argcd的cluster列表中 argocd cluster add kubernetes-admin@i ...
- Windows OhmGraphite 配置
Windows OhmGraphite 配置 由于windows_exporter无法监控温度相关的指标,那么就需要使用OhmGraphite进行监控该指标. 下载 访问 https://github ...
- JS 这一次彻底理解选择排序
壹 ❀ 引 我在 JS 这一次彻底理解冒泡排序 一文中介绍了十大经典排序中的冒泡排序,所谓冒泡排序就是不断比较相邻的两个元素,让较小的往前浮,较大的往后沉,直到所有元素找到自己对应的位置.那么现在我们 ...