A-vasya and Socks Time
limit:1000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u Submit Status Practice codeforces 460A
Description
Vasya has n pairs of socks. In the morning of all day Vasya have 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 with numbers m, 2m, 3m, ...) mom buys a pair of socks To Vasya. She does it late in the evening, so this 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 the integers n and m(1≤ n ≤ 100; 2≤ m ≤ separated by a space.
Output
Print a single integer-the answer to the problem.
Sample Input
Input
2 2
Output
3
Input
9 3
Output
13
First on the test instructions: Vasya have n pairs of socks, local tyrants Vasya wear a pair every day, through the throw away, Vasya mother every m days to buy her a pair of new socks, asked Vasya when no socks to wear.
The AC code is attached:
1#include <iostream>2#include <cstdio>3#include <cmath>4 using namespacestd;5 6 intMain () {7 intn,m;8 while(~SCANF ("%d%d",&n,&m)) {9 inti,ans=0;Ten for(i=1; n;i++){ One A if(i%m==0){ -n++; - } then--; - } -printf"%d\n", I-1);//note here to reduce one - + } - return 0; +}
A-vasya and Socks