# FIVECOIN - Editorial

**URL:** <https://discuss.codechef.com/t/fivecoin-editorial/126134>\
**Category:** editorial\
**Tags:** cakewalk, editorial, start263\
**Created:** [November 4, 2026, 4:30pm UTC](https://discuss.codechef.com/t/fivecoin-editorial/126134 "2026-11-04T16:30:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceknight1093](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@iceknight1093](https://discuss.codechef.com/u/iceknight1093)\
**Post date:** [November 4, 2026, 4:30pm UTC](https://discuss.codechef.com/t/fivecoin-editorial/126134/1 "2026-11-04T16:30:19Z")

</div>

# PROBLEM LINK:

[Practice](https://www.codechef.com/problems/FIVECOIN)  
[Contest: Division 1](https://www.codechef.com/START263A/problems/FIVECOIN)  
[Contest: Division 2](https://www.codechef.com/START263B/problems/FIVECOIN)  
[Contest: Division 3](https://www.codechef.com/START263C/problems/FIVECOIN)  
[Contest: Division 4](https://www.codechef.com/START263D/problems/FIVECOIN)

_ **Author:** _ [iceknight1093](https://www.codechef.com/users/iceknight1093)  
_ **Tester:** _ [raysh07](https://www.codechef.com/users/raysh07)  
_ **Editorialist:** _ [iceknight1093](https://www.codechef.com/users/iceknight1093)

# DIFFICULTY:

Cakewalk

# PREREQUISITES:

None

# PROBLEM:

You have one five-rupee coin and an infinite number of one-rupee coins.  
Find the minimum number of coins needed to pay exactly N rupees to a shop.

# EXPLANATION:

If N \lt 5, we cannot use the five-rupee coin at all - so we must use one-rupee coins only.  
The answer in this case is N.

If N \ge 5, then in order to minimize the number of coins used it’s optimal to always use the five-rupee coin.  
The remaining amount must be paid using one-rupee coins.  
So the answer in this case is

1 + N-5

Check whether N \lt 5 or N \ge 5 using an `if` condition and print the answer appropriately.

# TIME COMPLEXITY:

\mathcal{O}(N) per testcase.

# CODE:

> **Editorialist's code (PyPy3)**
>
> ```python
> n = int(input())
> print(n if n < 5 else n-4)
> 
> ```
