Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)
题目链接:http://codeforces.com/contest/460/problem/A
1 second
256 megabytes
standard input
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?
The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100),
separated by a space.
Print a single integer — the answer to the problem.
2 2
3
9 3
13
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;
}
最新文章
- 【原创】js中input type=file的一些问题
- 【转】Linux下apache/httpd服务启动与停止
- C# 操作鼠标移动到指定的屏幕位置方法
- Java RSA 密钥生成工具
- 焦点问题onfocus=”this.blur()”代替方法(转)
- 23、jQuery九类选择器/jQuery常用Method-API/jQuery常用Event-API
- Windows环境下安装IPython NoteBook
- Asp.Net WebAPI 通过HttpContextBase获取请求参数
- 2.Redis的基本配置
- python之--------封装
- 【Windows】关于shift跟空格同时按无反应的解决方案
- 「译」图解 ArrayBuffers 和 SharedArrayBuffers
- Python科学计算基础包-Numpy
- ios 自动化构建 code-select: error: tool &#39;xcodebuild&#39; requires Xcode, but active developer directory.....
- SQL LEN() 函数
- Java框架spring 学习笔记(三):Bean 的生命周期
- 管理菜单 结贴回复 来自 202.112.36.253 的回复: TTL 传输中过期
- mySQL 判断表是否存
- JAVA 8 主要新特性 ----------------(二)JDK1.8优点概括
- [20180627]测试bbed是否支持管道命令.txt
热门文章
- CentOS6配置静态IP
- HDU 5536 Chip Factory
- python3--__call__拦截调用
- hdu2063 二分图匹配,匈牙利算法
- 07-复习数组和简单api
- Android点击两次返回退出程序
- 【bzoj1109】[POI2007]堆积木Klo 动态规划+树状数组
- [BZOJ2523][Ctsc2001]聪明的学生
- Mychael原创题 洛谷T23923 Mychaelの水题 【题解】
- 洛谷P3327 - [SDOI2015]约数个数和