A - Vasya and Socks

A - Vasya and Socks
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Input
2 2
Output
3
Input
9 3
Output
13

先上题意: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\n",i-1);//此处注意减一 
18         
19     }
20     return 0;
21 } 

 

posted @ 2016-05-14 16:39  Kiven#5197  阅读(261)  评论(0编辑  收藏  举报