#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int main() {
  scanf("%d%d", &a, &b);
  while (b) {
    c = b % a;
    if (!c) {
      b /= a;
    } else if (c == 1) {
      b = (b - 1) / a;
    } else if (c == a - 1) {
      b = (b + 1) / a;
    } else {
      puts("NO");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
