#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  while (b) {
    int c = b % a;
    if (c == 0)
      b /= a;
    else if (c == 1)
      b--;
    else if (c == a - 1)
      b++;
    else
      return cout << "NO", 0;
  }
  cout << "YES";
  return 0;
}
