D - New Year Candles

发布时间:2017-2-27 19:23:08 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"D - New Year Candles",主要涉及到D - New Year Candles方面的内容,对于D - New Year Candles感兴趣的同学可以参考一下。

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; }