Test instructions
Give you w,n, ask you in w^0,w^1,w^2 ... all kinds of one, ask you can use these weights and the weight of things put on the balance of the balance to make balances;
Ideas:
This is easy to associate with the binary:
If you put M on the side, in fact, the weights are purely additive, can be expressed as such a binary, each bit is 0 or 1
So if both sides are going to put it.
So how am I going to use M and what I already have, to construct a binary number that's only 01
Why do you say that? Because the right side of the left is equivalent AH;
Then from low to high processing, to ensure the use of weights <=1;
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>pii;
const double eps=1e-5;
Const double Pi=acos ( -1.0);
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int w,n;
int bit[35];
int num;
void init ()
{
num=0;
while (n)
{
bit[num++]=n%w;
n/=w;
}
}
int main ()
{
scanf ("%d%d", &w,&n);
Init ();
for (int i=0;i<num;i++)
{
if (bit[i]>=w)
{
bit[i]-=w;
bit[i+1]++;
}
if (bit[i]<=1) //0 is used, 1 is not
continue;
else if (bit[i]==w-1) //and M side of +w^ (i-1) makes the other side as long as +w^i on the line;
bit[i+1]++;
Else
{
puts ("NO");
return 0;
}
}
Puts ("YES");
return 0;
}