Codeforces 617A Elephant Solution & Explanation

Difficulty : 800

Problem Description

An elephant decided to visit his friend. It turned out that the elephant’s house is located at point 0 and his friend’s house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend’s house.

Input

The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend’s house.

Output

Print the minimum number of steps that elephant needs to make to get from point 0 to point x.

Examples

Input5
Output1
Input12
Output3

Solution

We need to find the minimum number of steps required to reach the destination, so we will choose the largest step size that doesn’t exceed the distance, and that maximum step size is 5, and then perform the calculation.

C# Solution

Solution1

int n = int.Parse(Console.ReadLine());
int res = n/5+(n%5==0?0:1);

Console.WriteLine(res);

Java Solution

Solution1

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        
        System.out.println(n/5+(n%5==0?0:1));
        
    }
}

Python3 Solution

Solution1

n = int(input())

print(n//5+(0 if n%5==0 else 1))

In Python, you need to use floor division to avoid getting a floating-point result.

JavaScript Solution

Solution1

var n = readline();

print(Math.floor(n/5)+(n%5===0?0:1));

Conclusion

🧡If my solution helps, that is my honor!

🧡You can support me by sharing my posts, thanks you~~

✅If you got any problem about the explanation or you need other programming language solution, please feel free to let me know !!

The problem link : Problem – 617A – Codeforces

Random Codeforces Posts

2 Comments

  1. The answer to the following question is just amazing.
    Is it trivial to come to this approach naturally because I followed the ( if Total – max(1,2,3,4,5) >= 0 ) approach. However, I also solved the problem but your way is just too precise and wonderful.

    Can you suggest some practice methods?

    • Thank you for your praise! I’m really glad my solution was helpful to you. If you’re looking to keep challenging yourself, I recommend trying out the Blind75 series on LeetCode. These problems are very targeted and can be quite helpful for interview preparation, especially for practicing with strings, arrays, binaries, and other concepts. While Codeforces is also a great platform, I find LeetCode problems are usually a bit easier to read and comprehend, which can be very beneficial for understanding and practice. Hope you enjoy it!

Leave a Reply

Your email address will not be published. Required fields are marked *