Tuesday, May 3, 2011

10346 - Peter's Smokes


#include<stdio.h>
int main()
{
    register unsigned long n,k,t,b;
    //freopen("in.txt","r",stdin);
    while(scanf("%lu%lu",&n,&k)==2)
    {
        t=b=0;
        while(n)
        {
            t=t+n;
            b=b+n;
            n=b/k;
            b=b%k;
        }
        printf("%lu\n",t);
    }
    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.