#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007LL;
const long long INF2 = 1000000007LL * 1000000007LL;
const long double EPS = 1e-9;
const int SIZE = 1000100;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1000000000, 1000000000);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long w, m, d;
  cin >> w >> m;
  while (m > 1) {
    d = m % w;
    if (d == 0)
      m /= w;
    else if (d == 1)
      m = (m - 1) / w;
    else if (d == w - 1)
      m = (m + 1) / w;
    else
      break;
  }
  cout << (m == 1 ? "YES" : "NO");
  return 0;
}
