1.21 A

A - 1

Time limit 1000 ms
Memory limit 262144 kB

Problem Description

Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, …) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?

Input

The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.

Output

Print a single integer — the answer to the problem.

Sample Input

2 2

9 3

Sample Output

3

13

问题链接:A - 1

问题简述:

输入n和m,分别表示原本有的袜子数和败家女孩妈妈每m天买一双新的袜子,问多少天之后没有袜子穿

问题分析:

让天数sum随n递减而自增,同时每m次就额外让n自增,完成买新袜子的指令,最好不要分开计算会使问题变复杂一开始就因为分开算AC不了

程序说明:

while(n–)是关键,sum和buy分别是答案输出的天数和用于判断每m天让n自增的天数,最后输出sum即可

AC通过的C语言程序如下:

#include <iostream>
using namespace std;

int main()
{
	int n, m;
	int sum = 0;
	cin >> n>> m;
	int buy = 0;
	while (n--)
	{
		sum++;
		buy++;
		if (buy%m == 0)
		{
			n++;
		}
	}
	cout << sum;
}

猜你喜欢

转载自blog.csdn.net/weixin_44003969/article/details/86574905