您的位置:首页 > 其它

D - New Year Candles

2014-02-18 20:55 288 查看
Description

Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.

Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make bwent
out candles into a new candle. As a result, this new candle can be used like any other new candle.

Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.

Input

The single line contains two integers, a and b(1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).

Output

Print a single integer — the number of hours Vasily can light up the room for.

Sample Input

Input
4 2


Output
7


Input
6 3


Output
8

分析:其实这道题认真读不难的,水题。大意是:a根蜡烛,b根烧剩的蜡烛能变成一根新蜡烛,一根烧一小时,问能烧几小时。
下面给参考代码:
#include <stdio.h>

int main()

{

    int a, b,sum=0,leave=0;

    scanf("%d %d",&a,&b);

    while(a)

    {

        sum+=a;

        leave+=a;

        a=leave/b;

        leave%= b;

    }

    printf("%d\n", sum);

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: