A-vasya and Socks

Source: Internet
Author: User

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

Related Article

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.