Codechef Problems: Exercise and Rest (EXREST)

 Problem Statement: 

Chef is on a new exercise plan: he'll work out for two days, then take one rest day, and then repeat.

Today is Chef's N-th rest day. How many days (including today) has it been since Chef started his plan?

Input Format

  • The only line of input contains a single integer N.

Output Format

Output a single integer: the number of days that have passed since Chef started his exercise plan.

Constraints

  • 1N10

Solution: 

Given, N : Represents the number of rest days (today is Nth rest day) 

Let's solve this problem by Intution: 

suppose today is 1st rest day then the Exercise plan will be 
day 1 - Workout day 
day 2 - Workout day 
day 3 - Rest day (1st Rest day) 
then total number of days in exercise plan will be 3. 

Then again suppose today is 3rd rest day then the Exercise plan will be
day 1 - Workout day 
day 2 - Workout day
day 3 - Rest day (1st Rest day)
day 4 - Workout day 
day 5 - Workout day 
day 6 - Rest day (2nd Rest day) 
day 7 - Workout day 
day 8 - Workout day 
day 9 - Rest day (3rd Rest day) 
total number of days in exercise plan will be 9 

similarly for nth rest day 
day 1 - workout day 
day 2 - workout day 
day 3 - 1st rest day 

day 4 - workout day 
day 5 - workout day 
day 6 - 2nd rest day 

...

day 3n - 2 : workout day 
day 3n - 1 : workout day 
day 3n : nth rest day 

total number of days in exercise plan will be 3*n 

Hence, the solution of this problem is 3*N where N is the number of present rest day 

Code Solution

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;

    cout << 3 * n << endl;
}

Comments

Popular posts from this blog

Codechef Problems: Triangles (TRIANGLE7)

Codechef problems : New Year Resolution (NYRES)

Codechef Problems: Selling Sandwiches (SANDWSHOP)