#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <time.h>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <fstream>
#include <queue>
#define mp make_pair
#define pb push_back
#define PI 3.14159265358979323846
#define MOD 1000000007
#define INF ((ll)1e+15)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
typedef long long ll;
using namespace std;
ll w,m,sz,i;
ll a[40];
int main()
{
ll flag = 1;
cin >> w >> m;
while (m)
{
a[sz++] = m%w;
m /= w;
}
for (i = 0; i <= sz; i++)
if (a[i] != 0 && a[i] != 1 && a[i] != w-1 && a[i] != w)
{
flag = 0;
break;
}
else
{
if (a[i] == w-1 || a[i] == w)
a[i+1]++;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDx0aW1lLmg+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8cXVldWU+CiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgUEkgMy4xNDE1OTI2NTM1ODk3OTMyMzg0NgojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CiNkZWZpbmUgSU5GICgobGwpMWUrMTUpCiNkZWZpbmUgeDEgZmxkZ2pkZmxnamhydGhybAojZGVmaW5lIHgyIGZsZGdqZGZsZ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