Multiple of 3
Given a positive integer $N$, find the nearest multiple of $3$. Multiples of $3$ are $\ldots -6, -3, 0, 3, 6, 9, 12, 15, \ldots$. Formally, find $X$, the multiple of $3$ with minimum value of $|N - X|$. It can be proven that the answer is always unique, i.e. $2$ different multiples of $3$ cannot be nearest at the same time. ### Input - The only line of input contains a single integer $N$. ##
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.
Sign in to chat with the tutor and save your progress.
Sign in to start