#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int w;
  cin >> w;
  long long int n;
  cin >> n;
  int counter = 0;
  while (true) {
    if (counter > 100) {
      cout << "NO" << endl;
    }
    if (n == 1) {
      cout << "YES" << endl;
      break;
    }
    if (n % w == 0) {
      n = n / w;
    } else if (n % w == 1) {
      n = n - 1;
      n /= w;
    } else if (n % w == (w - 1) || n % w == -1) {
      n = n + 1;
      n /= w;
    } else {
      cout << "NO" << endl;
      break;
    }
    counter++;
  }
}
