#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, w;
  cin >> w >> n;
  if (w <= 3) {
    cout << "YES" << endl;
    return 0;
  }
  while (n > 0) {
    if (n % w > 1 && n % w < w - 1) {
      cout << "NO" << endl;
      return 0;
    }
    n = (n + 1) / w;
  }
  cout << "YES" << endl;
  return 0;
}
