CodeForces 460 A. Vasya and Socks(379A.New Year Candles)
来源:互联网 发布:淘宝大学金牌讲师小飞 编辑:程序博客网 时间:2024/05/19 13:20
A. Vasya and Socks
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.
百度翻译:Vasya有N双袜子。在每一天早上有Vasya上学之前穿上一双袜子。当他晚上回到家,Vasya脱下袜子扔了。每一个m天(天数m, 2m,3m, …)妈妈买了一双袜子,Vasya。她在晚上,所以Vasya不能穿上一双新袜子在明天之前。多少天过去直到Vasya耗尽的袜子吗?
输入
一行包含两个整数n和m(1 ≤ N ≤ 100;2 ≤ M ≤ 100),用一个空格隔开。
输出
打印一个整数——问题的答案。
实例
输入
2 2
输出
三
输入
9 3
输出
十三
注
在第一个样品Vasya花的头两天穿,他最初的袜子。然后在第三天,他穿上了第二天买的袜子。
在样本二Vasya花的前九天,他开始穿袜子。然后他花了三天穿上第三、第六、第九天买的袜子。他花了一天的时间穿上第十二天买的袜子。
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int sum=0,i,j;
for(i=n,j=1;i>0;i--,j++)
{
if(j%m==0)
i++;
sum++;
}
printf("%d\n",sum);
return 0;
}
- CodeForces 460 A. Vasya and Socks(379A.New Year Candles)
- codeforces-379A. New Year Candles
- Codeforces 379A New Year Candles(模拟)
- CodeForces-379A-New Year Candles
- CodeForces 379A. New Year Candles
- codeforces 379A New Year Candles(水题)
- CodeForces 379 A.New Year Candles(水~)
- 379A - New Year Candles
- Problem--379A--Codeforces--A. New Year Candles
- codeforces-#460A Vasya and Socks
- Codeforces 460A Vasya and Socks(水题)
- CodeForces-460A-Vasya And Socks
- Codeforces A. Vasya and Socks
- A. New Year Candles
- codeforces -- goodbye2013 ---A. New Year Candles
- CF 379A New Year Candles
- 460A Vasya and Socks
- 460 A. Vasya and Socks
- flume简介
- Meeting HDU
- SP375 Query on a tree【树链剖分】
- Python 脚本错误:IndentationError: unindent does not match any outer indentation level
- hdu1269迷宫城堡(tarjan模板)
- CodeForces 460 A. Vasya and Socks(379A.New Year Candles)
- CodeForces 827D 浅谈最小生成树性质解析及题目性质分析
- Qt中的loader
- Spring-Boot-Valid的使用
- python写数据到外部文件
- python运维_third_chapter(2)
- CentOS安装gcc/g++
- Java Socket学习(一)——Socket简单连接
- VMware10 安装Centos6.5(64位) 详细步骤