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