Solution
- 按位判断
- 考虑w进制借位
Sample Code
#include <bits/stdc++.h>
using namespace std;
int w, m;
void Do(){
if(w == 1) {
cout << "YES" << endl;
return;
}
int tmp = m; int addition = 0;
while(tmp){
int cur = tmp % w;
tmp /= w;
cur += addition;
if(cur != 1 && cur != 0 && cur != w - 1 && cur != w){
cout << "NO" << endl;
return;
}
if(cur == w - 1 || cur == w) addition = 1;
else addition = 0;
}
cout << "YES" << endl;
return;
}
int main(){
cin >> w >> m;
Do();
return 0;
}