← All problemsSign in

Imperfect Numbers

CodeChefRating 697Open on judge ↗

Chef calls a **positive** integer *imperfect* if it's divisible by **either** $2$ or $5$, but **not both**. For example, $8$ and $15$ are *imperfect* integers, while $20$ is not. You are given an integer $N$. Find the **minimum** possible difference between $N$ and an *imperfect* number. That is, find the minimum possible value of $|N - M|$ across all choices of $M$ that are *imperfect* numbe

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start