UVa 10346 Peter ' s smokes (water ver.)

Source: Internet
Author: User
Tags integer numbers time limit

10346-peter ' s smokes

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1287

Peter has n cigarettes. He smokes them one by one keeping all the butts. Out OFK > 1 butts He can roll a new cigarette.

How many cigarettes can Peter have?

Input

The Input is a sequence of lines. Each line contains two integer numbers giving the values ofn and K. The ' input is terminated by ' file.

Output

For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter CA N have.

Sample Input

4 3
10 3
100 5

Sample Output

5
14
124

Complete code:

/*0.018s*/
  
#include <cstdio>
  
int main ()
{
    int n, k, I;
    while (~SCANF ("%d%d", &n, &k))
    {for
        (i = n; i >= k; i = i% k + i/k) n + = i/k;
        printf ("%d\n", n);
    }
    return 0;
}

Author: csdn Blog Synapse7

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.