题面

链接

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. C# Switch优雅写法

    1 private static bool CanBeUpdateOrDel(bool 是否提交, bool 是否撤回, string 审核状态) => (是否提交, 是否撤回, 审核状态) s ...

  2. 金融领域:产业链知识图谱包括上市公司、行业和产品共3类实体,构建并形成了一个节点10w+,关系边16w的十万级别产业链图谱

    金融领域:产业链知识图谱包括上市公司.行业和产品共3类实体,构建并形成了一个节点10w+,关系边16w的十万级别产业链图谱 包括上市公司所属行业关系.行业上级关系.产品上游原材料关系.产品下游产品关系 ...

  3. 文档级关系抽取:基于结构先验产生注意力偏差SSAN模型

    文档级关系抽取:基于结构先验产生注意力偏差SSAN模型 Entity Structure Within and Throughout: Modeling Mention Dependencies fo ...

  4. win10安装wget,从此可以更快的下载文件 and windows10 下 zip命令行参数详解

    1.win10安装wget 1.1安装下载 GNU Wget 1.21.3 for Windows 依次如下: 2.将下载好的wget.exe放到 C:/windows/system32文件夹下 也可 ...

  5. 【四】多智能体强化学习(MARL)近年研究概览 {Learning cooperation(协作学习)、Agents modeling agents(智能体建模)}

    相关文章: [一]最新多智能体强化学习方法[总结] [二]最新多智能体强化学习文章如何查阅{顶会:AAAI. ICML } [三]多智能体强化学习(MARL)近年研究概览 {Analysis of e ...

  6. C/C++ 原生套接字抓取FTP数据包

    网络通信在今天的信息时代中扮演着至关重要的角色,而对网络数据包进行捕获与分析则是网络管理.网络安全等领域中不可或缺的一项技术.本文将深入介绍基于原始套接字的网络数据包捕获与分析工具,通过实时监控网络流 ...

  7. MyISAM存储引擎的表级锁

    MyISAM存储引擎的表级锁 如果了解过文件锁的用法,那理解数据库锁就简单了.锁其实就协调多个进程或线程并发时,处理访问同一个资源的机制.在项目开发中,表锁是MySQL中作用范围较大的一种锁,它锁定的 ...

  8. 交换变量a,b的值(java)

    方法1:引入中间变量 int a = 10; int b = 20; int temp = a; a = b; b = temp; System.out.println("a = " ...

  9. 洛谷P1102 过河卒

    P1102 过河卒 链接在此 过河卒 此题如果直接忽略掉马的影响的话,可以看出很简单的递推规律 即 \[dp[i][j]=dp[i-1][j]+dp[i][]j-1] \] 也就是说,由于卒只能走直线 ...

  10. 6.用户输入和 while 循环--《Python编程:从入门到实践》

    6.1 input 函数 函数input()接受一个参数:即要向用户显示的提示或说明.input 将用户输入解释为字符串. name = input("Please enter your n ...