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.

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.

【代码】:

#include <bits/stdc++.h>

using namespace std;
int sum;
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=n,j=;i>=;i--,j++)//i:袜子个数
{
if(j%m==)
i++;
sum++;
}
cout<<sum<<endl;
}
return ;
}

双指针

#include <bits/stdc++.h>

using namespace std;

int main()
{
int n,m;
while(cin>>n>>m)
{
int day=;
int k=;
while(n--)//袜子消耗
{
if(day%m==)
{
n++;//当是m的倍数的时候再购进一双袜子
}
day++;//不管有没有袜子穿日子总要过下去
k++;//维持的日子
}
printf("%d\n",k);
}
return ;
}

多变量记录

Codeforces Round #262 (Div. 2) A. Vasya and Socks【暴力/模拟/袜子在可以在合法情况下增加后用几天】的更多相关文章

  1. codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子, ...

  2. Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

    题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second mem ...

  3. Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

    A. Vasya and Football   Vasya has started watching football games. He has learned that for some foul ...

  4. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  6. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  7. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  8. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  9. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

随机推荐

  1. java和c/c++

    写c/c++的人,羡慕java可以自己管理内存 写java的人,羡慕c/c++没有gc问题

  2. 安卓Dex壳技术探讨(1)

    最近在研究安卓平台的加壳技术,以前以为只有原生层的代码才可以加壳,看了看网上的资料,才发现原来Java层也可以加壳,虽然与传统的壳有些区别,但就最终的效果来说,反静态分析的目的还是达到了的. 目前安卓 ...

  3. linux_shell基础-变量、数组、运算符

    #!/bin/bash# echo 'hello world'# name='http://www.baidu.com'# for file in $(ls ./); do# echo "t ...

  4. 关于windows10设置环境变量的问题

    在设置环境变量的时候往往在网上能找到这样的文章: 1:新建环境变量 2:将新增的环境变量 加到path 变量中: 3.由于有的小伙伴的 系统是 windows10 在点击 编辑path 环境变量的时候 ...

  5. Fomo3D代码分析以及漏洞攻击演示

    Fomo3D过去的一周内赚足了噱头,一场光明正大的"庞氏"游戏疯狂吸金,在链得得此前的报道中提到"Fomo3D的开发者,是对生态有深刻理解的现实主义者.Fomo3D鼓励黑 ...

  6. php + ajax实现 帖子点赞功能

    知识: 一.首先页面需要加载jquery框架 二.ajax常用参数解释: ①.type:传输数据方式,get或者post ②.url:处理数据的PHP脚本 ③.data:传输的数据索引及值,值用js获 ...

  7. 【Luogu】P2490黑白棋(博弈DP)

    题目链接 题解链接 #include<cstdio> #include<cstring> #include<algorithm> #include<cstdl ...

  8. joyOI 选课 【树形dp + 背包dp】

    题目链接 选课 题解 基础背包树形dp #include<iostream> #include<cstdio> #include<cmath> #include&l ...

  9. [TJOI2007] 线段 (动态规划)

    题目链接 Solution 传统的线性 \(dp\) . \(f[i][0]\),\(f[i][1]\) 分别表示最后一次在 \(i\) ,然后在 左边或者右边的最小步数. 然后就每次根据上一次左边和 ...

  10. mysql如何更改character-set-server默认为latin1

    运行环境:win10 mysql版本:MYSQL5.7免安装版(或解压版) 今天在学习mysql字符集有关乱码的知识 然后发现了latin1的字符集编码格式,虽然命令行窗口改变很容易,只需两行命令 s ...