1 10 3
10
#include <stdio.h> typedef long long ll ; ll kill(ll n , ll k) { if(n == k) { return k ; } ll x = (kill(n-n/k,k)) ; return (x-1)/(k-1)+x ; } int main() { ll n , k ; int t ; scanf("%d",&t) ; while(t--) { scanf("%I64d%I64d",&n,&k) ; ll ans = kill(n,k) ; printf("%I64d\n",ans) ; } return 0 ; }
原文地址:http://blog.csdn.net/lionel_d/article/details/44837547