#include <bits/stdc++.h>
using namespace std;
int w;
bool possible(int m) {
  if (m <= 1) return true;
  int rem = m % w;
  if (rem == 0 || rem == 1)
    return possible(m / w);
  else if (rem == w - 1)
    return possible((m + 1) / w);
  else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  int m;
  scanf("%d %d", &w, &m);
  if (possible(m))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
