#include <bits/stdc++.h>
using namespace std;
int w, m;
int n = 100;
bool bal(int i, vector<int> p1, vector<int> p2) {
  if (i == n) return 0;
  long long p11 = 0, p22 = 0;
  for (int j = 0; j < p1.size(); j++) p11 += pow((double)w, p1[j]);
  for (int j = 0; j < p2.size(); j++) p22 += pow((double)w, p2[j]);
  if (p11 + m == p22) return true;
  bool c1 = bal(i + 1, p1, p2);
  p1.push_back(i);
  bool c2 = bal(i + 1, p1, p2);
  p2.push_back(i);
  p1.pop_back();
  bool c3 = bal(i + 1, p1, p2);
  return c1 || c2 || c3;
}
int main() {
  cin >> w >> m;
  if (m == 1 || m == w - 1) {
    cout << "YES";
    return 0;
  }
  while (true) {
    int m1 = m % w;
    if (m1 == w - 1) {
      m = m / w + 1;
    } else if (m1 == 0 || m1 == 1) {
      m = m / w;
    } else {
      cout << "NO";
      return 0;
    }
    if (m == 0 || m == w - 1) {
      cout << "YES";
      return 0;
    }
  }
  system("pause");
  return 0;
}
