#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
long long fP(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power & 1) {
      result = result * base % mod;
    }
    power >>= 1;
    base = (base * base) % mod;
  }
  return result;
}
using namespace std;
const long long maxn = 1e5 + 50;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  if (m == 1) {
    cout << "YES" << endl;
    return 0;
  }
  long long z = 0;
  while (m) {
    if (m == 1) {
      cout << "YES" << endl;
      return 0;
    }
    if (m % n == 0) {
      m /= n;
      continue;
    } else {
      if ((m + 1) % n == 0) {
        m += 1;
        m /= n;
        continue;
      } else if ((m - 1) % n == 0) {
        m -= 1;
        m /= n;
        continue;
      } else {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
