#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int w, n;
  cin >> w >> n;
  int cnt = 0;
  while (cnt < 200) {
    cnt++;
    if (n == 1) break;
    if (n % w == 0)
      n = n / w;
    else if ((n + 1) % w == 0)
      n = (n + 1) / w;
    else if ((n - 1) % w == 0)
      n = (n - 1) / w;
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  if (cnt <= 100)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
