#include <bits/stdc++.h>
using namespace std;
long long int w, m;
bool f(long long int x) {
  if (x > m)
    return false;
  else if (x == m)
    return true;
  else
    return (f(w * x) || f(w * x + 1) || f(w * x - 1));
}
int main() {
  cin >> w >> m;
  if (w < 4)
    cout << "YES";
  else if (f(1))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
