#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; #include #include namespace mp = boost::multiprecision; using Bint = mp::cpp_int; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); Bint n,k,m; cin>>n>>k>>m; Bint ans=0; Bint t=m; while(n/t>=1){ ans+=n/t; t*=m; } t=m; while(k/t>=1){ ans-=k/t; t*=m; } t=m; while((n-k)/t>=1){ ans-=(n-k)/t; t*=m; } cout<