#include using namespace std; using ll = long long; using P = pair; #define rep(i, n) for(int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> a[0] >> a[1] >> m; ll ans = 0; a[2] = a[0] - a[1]; rep(i,3){ while(a[i]){ a[i] /= m; if(i) ans -= a[i]; else ans += a[i]; } //cout << ans << endl; } cout << ans << endl; return 0; }