#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> n >> k >> m; ll ans = 0, k2 = n-k; while(n){ ans += n / m; n /= m; } while(k){ ans -= k / m; k /= m; } while(k2){ ans -= k2 / m; k2 /= m; } cout << ans << endl; return 0; }