# include<bits/stdc++.h>
using namespace std;

int main()
{
  int a,b,c=0;set<int>s;
  cin>>a>>b;

  while(a)
  {
    c++;
    s.insert(a%b);
    a/=b;
  }
  if(c==s.size())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;

  return 0;
}
