Little Monkey Programming C++ | Morning Run

Learn C++ from a young age! Record the questions in the learning process of Xueersi Monkey programming and record every moment. Any infringement will be deleted immediately, thank you for your support!

Attached is a summary post: Little Monkey Programming C++ | Summary-CSDN Blog


[Title description]

Xiaohou is a primary school student who loves sports and runs on the treadmill every morning.

The total running time of the little monkey every day is  T. Because he is still a primary school student, he cannot run for too long, at most  R  minutes. However, in order to achieve the exercise effect, he cannot run for too short time, so he must run for at least  L  minutes. Then it is necessary to ensure  that LTR .

The little monkey will have several groups of running plans every day, and the duration of each group's running plan is  n , ensuring that  nL. But the little monkey has a habit: if there is not enough time left to complete a complete running plan, then he will stop the remaining training today (that is, the last group will not run) and go to have breakfast.

The little monkey's mother will randomly  select an integer  T between LR  (including  L  and  R )  every day as the total running time of the little monkey that day, but the little monkey's mother hopes that the little monkey will not be able to complete a set of running plans every day. Make it as long as possible so that the monkey has enough time to eat breakfast.

As the mother of a high-quality child, the monkey's mother decided to write a program that inputs  n , L , and R in sequence, and outputs the maximum duration of a set of running plans that the monkey cannot complete that day.

【enter】

A line contains three integers  n , L , R. See the title description for its meaning .

【Output】

A line containing an integer representing the result.

【Input sample】

5 13 26

【Output sample】

4

[Detailed code explanation]

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, l, r;
    cin >> n >> l >> r;
    if (l/n == r/n) cout << r%n;
    else {
        cout << n-1;
    }
    return 0;
}

【operation result】

5 13 26
4

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/133914691