#include <cstdio>
int a, b;
int num[20], mark;
int main () {
    scanf ("%d%d", &a, &b);
    while (a) {
        num[a % b]++;
        a /= b;
    }
    for (int i = 0; i < b; i++) {
        if (num[i] > 1) return puts("NO"),0;
    }
    puts("YES");
}