#include <bits/stdc++.h>
int main() {
  long long base, goal;
  std::cin >> base >> goal;
  long long sum = 0, logged = 0;
  while (goal >= 1 and logged <= 100) {
    long long remainder = goal % base;
    if (remainder == 1) {
      sum += 1;
    } else if (remainder == base - 1) {
      goal += 1;
    } else if (remainder == 0) {
    } else {
      std::cout << "NO";
      return 0;
    }
    goal /= base;
    sum /= base;
    logged++;
  }
  std::cout << "YES";
  return 0;
}
