寒假5.1

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.
Examples
Input
2 2
Output
3
Input
9 3
Output
13

Note
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.

本题只需要判断n是非有增加即可,若达到相应天数,即增加袜子数量。

#include<iostream>
using namespace std;
int main()
{
    int n, m, x=0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        if (i%m == 0)
        {
            n++;
        }
        x++;
    }
    cout << x;
    return 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. 关于诊断X线机准直器的作用,错误的是()。 (6.0 分) A. 显示照射野 B. 显示中心线 C. 屏蔽多...
    我们村我最帅阅读 13,708评论 0 5
  • 201. M-Q型显影液组合是()。 (2.0 分) A. 米吐尔与菲尼酮的组合 B. 对苯二酚和菲尼酮的组合 C...
    我们村我最帅阅读 9,161评论 0 4
  • 专业考题类型管理运行工作负责人一般作业考题内容选项A选项B选项C选项D选项E选项F正确答案 变电单选GYSZ本规程...
    小白兔去钓鱼阅读 12,944评论 0 13
  • 1. 下列叙述错误的是()。 (2.0 分) A. 质量管理包括QA和QC一切活动的全部过程 B. 影像质量是指对...
    我们村我最帅阅读 9,582评论 0 8
  • 离小区不远山坳里,有位养鸡的大叔;一般养有十几不到百来只鸡,价格卖25,35不等一斤;这样计算,一年下来虽不敢说很...
    josephzeng阅读 1,540评论 0 0