#include using namespace std; int main() { long long A,B,C; cin >> A >> B >> C; if(C==1){ cout << B*A << endl; return 0; } if(A v; long long D = C; while(A>0){ v.push_back(A%D); A /= D; } reverse(v.begin(),v.end()); long long ans = 0; ans += (int)v.size() - 1; for(int i = 0; i < v.size(); ++i) if(v[i]) ans += 1; cout << ans*B << endl; return 0; }