题面

链接

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. IM开源项目OpenIM部署文档-从准备工作到nginx配置

    IM开源项目OpenIM部署文档-从准备工作到nginx配置 2022-11-14 22:27·OpenIM 一.准备工作 运行环境 linux系统即可, Ubuntu 7.5.0-3ubuntu1~ ...

  2. TienChin 活动管理-修改活动接口

    前端 activity.js 直接替换现有的,最求速度了,后面在详细一个个记录,不在过多解释了. import request from '@/utils/request' /** * 查询活动列表 ...

  3. centos7下安装postgresql-10.3

    centos7下安装pgsql10.3 前言 下载pgsql-10.3 安装 解压 安装基本的工具 编译 安装 创建目录 data.log 加入系统环境变量 增加用户 postgres 并赋权 初始化 ...

  4. MySQL 存储过程与函数(精简笔记)

    MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RD ...

  5. ubuntu16.04编译安装nginx1.24.0

    环境: Distributor ID: Ubuntu Description: Ubuntu 16.04.7 LTS Release: 16.04 Codename: xenial 安装包: pcre ...

  6. TP5发送短信限制

    <?php //发送手机验证码 function smsCode() { //dump($this->request->post()); //请求方式验证 /*if (!$this- ...

  7. CF351D Jeff and Removing Periods 题解

    题目链接:CF 或者 洛谷 挺有意思的题,一开始看到了 \(start+k\times step\),以为是根号分治方向的题,结果发现这题还给了一个"重排"操作玩玩.所以这题其实算 ...

  8. Socket.D 协议的开发缘由

    为什么搞个新协议? 2021年时,想为 Solon 生态 提供一种 MVC 体验的 Socket 和 WebSocket 开发方式.这个想法,要求消息"能路由"."有元信 ...

  9. OpenGL的深度缓冲

      如果我们想要在三维空间里画两个正方形:一个红色的,一个绿色的,而且从人眼的观察角度看,绿色正方形在红色正方形的后面,最后看上去应该是这样的: 要点在于,从观察者的角度看,绿色正方形在红色正方形的后 ...

  10. Linux--如何查看磁盘的IO(top、iostat)

    问题背景: 在性能测试时,虽然测试出了结果,但是我们并不知道瓶颈是源端,还是目标端.例如我做上传和下载性能验证,从Linux服务器上向OSS集群上传和下载文件,虽然测试出了速率,但是并不知道上传是否存 ...