Link: http://codeforces.com/contest/460/problem/A
A. Vasya and sockstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Vasya hasNPairs 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. everyM-Th day (at days with numbersM,? 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 integersNAndM(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 under DS 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 specified DS the first nine days wearing the socks that he had initially. then he specified DS three days wearing the socks that were bought on the third, sixth and ninth days. than he has Ds another day wearing the socks that were bought on the twelfth day.
The Code is as follows:
//#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;}