I have written the following code for http://mirror.codeforces.com/problemset/problem/552/C
include<bits/stdc++.h>
using namespace std; typedef long long ll;
int main() { int i,j,k,l,m,n,w,f,t; cin>>w>>m;
while(m)
{
i=m%w;
m=m/w;
if(f==1)
i++;
f=0;
if(i==0 || i==1 || i==w)
{
}
else if(i==w-1)
{
f=1;
}
else
{
cout<<"NO";
return 0;
}
}
cout<<"YES";
return 0;
} Image link http://mirror.codeforces.com/predownloaded/57/61/5761486604e2ca57814ada50f20e298c3a8c764b.png
Test Case is: 116 Time: 15 ms, memory: 2020 KB Verdict: WRONG_ANSWER Input 10 899 Participant's output NO Jury's answer YES Checker comment wrong answer expected YES, found NO
****