#include <stdio.h> #include <stdlib.h>int main() {int now,k;while(scanf("%d %d",&now,&k) != EOF){int hav=0;while(now >= k){hav += now/k*k;now = now/k + now%k;}hav += now;printf("%d\n",hav);}return 0; }
算法思路:目前有几支烟就放进now中,把now看成一个整体,now对k取余和取商,商即为k支烟为大小的整体有多少个,一次就have掉now/k*k
now=now/k+now%k