#include <stdio.h>

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    int d[20] = {};
    while(n){
        int c = n%m;
        d[c]++;
        n /= m;
    }
    int ok = 1;
    for(int i=0; i<16; i++)
        if (d[i] > 1)
            ok = 0;
    if (ok)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}
