#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    int cnt = 0;
    set <int> s;
    while(n) {
        s.insert(n % m);
        cnt++;
        n /= m;
    }
    if(s.size() == cnt) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}
