#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
int i, j, k, n, m, res, kilk, cnt;
vector<int> nums;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  if (n < 3) return cout << "Yes" << '\n', 0;
  while (m) {
    if (m % n == 0 || m % n == 1)
      m /= n;
    else {
      if (m % n == n - 1)
        m = m / n + 1;
      else
        return cout << "No" << '\n', 0;
    }
  }
  cout << "Yes" << '\n';
  exit(0);
}
