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.


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


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




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


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


Java Solution


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(;
        int n = scanner.nextInt();

Python3 Solution


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


var n = readline();



🧡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


  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 *