题目链接:http://codeforces.com/contest/460/problem/A

A. Vasya and Socks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
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.

代码例如以下:

//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
int main()
{
int n, m;
while(~scanf("%d%d",&n,&m))
{
int i, j;
int sum = 0;
int tt = 0;
for(i = n,j = 1; i > 0; j++,i--)
{
if(j%m == 0)
i++;
sum++;
}
printf("%d\n",sum);
}
return 0;
}

最新文章

  1. 【原创】js中input type=file的一些问题
  2. 【转】Linux下apache/httpd服务启动与停止
  3. C# 操作鼠标移动到指定的屏幕位置方法
  4. Java RSA 密钥生成工具
  5. 焦点问题onfocus=”this.blur()”代替方法(转)
  6. 23、jQuery九类选择器/jQuery常用Method-API/jQuery常用Event-API
  7. Windows环境下安装IPython NoteBook
  8. Asp.Net WebAPI 通过HttpContextBase获取请求参数
  9. 2.Redis的基本配置
  10. python之--------封装
  11. 【Windows】关于shift跟空格同时按无反应的解决方案
  12. 「译」图解 ArrayBuffers 和 SharedArrayBuffers
  13. Python科学计算基础包-Numpy
  14. ios 自动化构建 code-select: error: tool &#39;xcodebuild&#39; requires Xcode, but active developer directory.....
  15. SQL LEN() 函数
  16. Java框架spring 学习笔记(三):Bean 的生命周期
  17. 管理菜单 结贴回复 来自 202.112.36.253 的回复: TTL 传输中过期
  18. mySQL 判断表是否存
  19. JAVA 8 主要新特性 ----------------(二)JDK1.8优点概括
  20. [20180627]测试bbed是否支持管道命令.txt

热门文章

  1. CentOS6配置静态IP
  2. HDU 5536 Chip Factory
  3. python3--__call__拦截调用
  4. hdu2063 二分图匹配,匈牙利算法
  5. 07-复习数组和简单api
  6. Android点击两次返回退出程序
  7. 【bzoj1109】[POI2007]堆积木Klo 动态规划+树状数组
  8. [BZOJ2523][Ctsc2001]聪明的学生
  9. Mychael原创题 洛谷T23923 Mychaelの水题 【题解】
  10. 洛谷P3327 - [SDOI2015]约数个数和