#include <bits/stdc++.h>
using namespace std;
void add(int& a, int b, int mod) { a = (a + b) % mod; }
void sub(int& a, int b, int mod) { a = ((a - b) % mod + mod) % mod; }
void mul(int& a, int b, int mod) { a = (a * 1ll * b) % mod; }
template <class T>
bool umin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool umax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
template <int sz>
using tut = array<int, sz>;
void usaco(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const long long inf = 1e18;
const long double Pi = acos(-1);
const long long MX = 1e6 + 6;
int n, m, k, t, q, ans, res, a[N];
int pw[N];
void solve(int t_case) {
  cin >> n >> m;
  pw[0] = 1;
  for (int i = 1; i <= 30; i++) {
    if (pw[i - 1] * 1ll * n < m) pw[i] = pw[i - 1] * n;
  }
  for (int x = m, i = 30; i >= 0; i--) {
    if (!pw[i]) continue;
    a[i] = x / pw[i], x %= pw[i];
  }
  for (int i = 0; i <= 30; i++) {
    if (a[i] == 1 || !a[i]) continue;
    a[i] -= n, a[i + 1]++;
    if (a[i] == -1 || a[i] == 0) continue;
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (0) {
    int t;
    cin >> t;
    for (int t_case = 1; t_case <= t; t_case++) solve(t_case);
  } else
    solve(1);
  return 0;
}
