提交时间:2023-01-20 20:36:48

运行 ID: 67905

#include<bits/stdc++.h> #define ll long long using namespace std; ll n,p,k; int main(){ freopen("set.in","r",stdin); freopen("set.out","w",stdout); scanf("%lld%lld%lld", &n, &k, &p); if(n<k){ printf("%lld", n*p); return 0; } ll tot=k,ans=k*p,tmp=k*k; for(int i=1;i<p;i++){ if(tot+tmp-tmp/k<n){ tot+=tmp-tmp/k; ans+=(tmp-tmp/k)*(p-i); } else { ans+=(n-tot)*(p-i); break; } tmp*=k; } printf("%lld", ans); return 0; }