1024: 手机话费

版权声明:越努力越幸运 https://blog.csdn.net/qq_41377858/article/details/86744628

题目描述
小明的手机每天消费1元,每消费K元就可以获赠1元,一开始小明有M元,问最多可以用多少天?
输入
输入包括多个测试实例。每个测试实例包括2个整数M,K(2<=k<=M<=1000)。M=0,K=0代表输入结束。
输出
对于每个测试实例输出一个整数,表示M元可以用的天数。
样例输入
2 2
4 3
0 0
样例输出
3
5

#include<iostream>

using namespace std;

int main(){
	int M,K;
	while(cin>>M>>K&&M&&K){
		int a=0;
		int count=0;
		while(M){
			M--,count++,a++;
			if(a==K){
				M++,a=0;
			}
		}
		
		cout<<count<<endl;
	}
	
	
	return 0; 
}

猜你喜欢

转载自blog.csdn.net/qq_41377858/article/details/86744628