Codeforces round #262 (Div. 2) 460a. Vasya and socks (simple mathematical problem)

Source: Internet
Author: User

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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.