📢 This article was translated by gemini-3-flash-preview
Problem Description
You have $n$ coins. One of them is a counterfeit and is known to be lighter than the genuine coins. Using only a balance scale, find the counterfeit coin with the minimum number of comparisons.
Problem Analysis
Divide the $n$ coins into two equal parts:
- If $n$ is even, place the two halves ($1\cdots\frac{n}{2}$ and $\frac{n}{2}+1\cdots n$) on each side of the scale. The counterfeit coin is in the lighter half. Continue the search within that half using the same method.
- If $n$ is odd, place the two halves ($1\cdots\frac{n-1}{2}$ and $\frac{n+1}{2}+1\cdots n$) on each side of the scale. If one side is lighter, the counterfeit coin is in that part; continue the search there. If the two sides balance, then the middle coin (the $\frac{n+1}{2}$-th coin) is the counterfeit one.
C Code
| |