CF1542B Plus and Multiply

Lisa

显然对于每一个时刻,可以调到的温度是一个区间

那么这样来做的话,我们只需要算出这个区间,然后去(∪)就可以了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define int long long 
using namespace std;
using namespace std;
int t;
int n,a,b;
signed main(){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld%lld%lld",&n,&a,&b);
		int tem=1;
		int f=0;
		if(a==1){
			if((n-1)%b==0){
				printf("YES
");
				continue;
			}else{
				printf("NO
");
				continue;
			}
		}
		while(tem<=n){
			if((n-tem)%b==0){
				printf("YES
");
				f=1;
				break;
			}else{
				tem*=a;
			}
		}
		if(!f){
			printf("NO
");
		}
	}
	return 0;
}
原文地址:https://www.cnblogs.com/For-Miku/p/15342219.html