Description
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 Input
Input2 2Output3Input9 3Output13
先上题意:vasya有n双袜子,土豪vasya每天穿一双,穿过的就扔掉,vasya的妈妈每m天给她买一双新的袜子,问vasya什么时候没有袜子穿。
附AC代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 6 int main(){ 7 int n,m; 8 while(~scanf("%d %d",&n,&m)){ 9 int i,ans=0; 10 for(i=1;n;i++){ 11 12 if(i%m==0){ 13 n++; 14 } 15 n--; 16 } 17 printf("%d ",i-1);//此处注意减一 18 19 } 20 return 0; 21 }