The answer is 2. One measurement is not enough even when we have only two boxes. Indeed, in this one measurement we could only fix in advance two numbers \(a_1\) and \(a_2\) and find the total weight of \(a_1\) coins from the first and \(a_2\) coins from the second box. We obtain the number \(M=a_1x+a_2y\), where \(w\in\{x,y\}\). Knowing \(M\), in general, we cannot conclude whether \(M=a_1p+a_2y\) or \(M=a_1x+a_2p\).
Let us now prove that we can find all fake coins in 2 measurements. In the first measurement we pick \(3^i\) coins from the box \(i\) and find their total weight \(M\). Denote \(N=3+3^2+\cdots + 3^n=\frac12(3^{n+1}-3)\). Let us consider two dfiferent cases: \(M < Nw\) and \(M > Nw\). Since the cases are very similar, we will consider only the first one.
We assume that \(M < Nw\). This means that the fake coins are lighter than the regular ones. Let us denote by \(f\) the weight of a fake coin. Then we have that \(M\geq Nf\) which means that \(f\leq \frac MN\). For any sequence \(\overrightarrow a=(a_1, \dots, a_n)\in \{0,1\}^n\) denote by \(T_{\overrightarrow a}=\sum_{i=1}^n a_i3^i\).
Denote by \(L\) the maximum of the set \(\left\{T_{\overrightarrow a}:\overrightarrow a\in\{0,1\}^n,\; T_{\overrightarrow a} < \frac N2\right\}\). Then we have that \(f\geq \frac{M-Lw}{N-L}\) thus \[\frac{M-Lw}{N-L}\leq f\leq \frac{M}N.\] We have that \(T_{\overrightarrow a}\neq T_{\overrightarrow{b}}\) whenever \(\overrightarrow a\neq \overrightarrow {b}\). Let us denote \(\omega=\min \left|\frac{T_{\overrightarrow a}}{T_{\overrightarrow{b}}}-1\right|\) where the minimum is taken over all pairs \((\overrightarrow a, \overrightarrow {b})\) that satisfy \(\overrightarrow a\neq \overrightarrow {b}\).
Lemma.
For every \(\varepsilon > 0\) we can use only one additional measurement to find a number \(\hat f\) such that \(|f-\hat f| < \varepsilon\).
Proof of Lemma.
Let us define the sequence \(\alpha_i\) recursively in the following way: \(\alpha_1 > \), and given \(\alpha_1\), \(\alpha_2\), \(\dots\), \(\alpha_{i-1}\) for \(i\geq 2\) we define \(\alpha_i\) to be any number such that \[\alpha_i\geq \max\left\{\frac{N}{N-L}\cdot (\alpha_1+\alpha_2+\cdots +\alpha_{i-1}), \frac{\alpha_1+\cdots + \alpha_{i-1}}{\varepsilon}\right\}.\] Let us introduce the notation:
\begin{eqnarray*}
A_i&=&(\alpha_1+\cdots+\alpha_{i-1})\cdot\frac{M-Lw}{N-L}+\alpha_iw,\\
B_i&=&(\alpha_1+\cdots+\alpha_{i-1})\cdot w+ \alpha_i\cdot \frac{M}N.
\end{eqnarray*}
The strategy is to pick \(\alpha_i\) coins from the box \(i\) for \(1\leq i\leq n\) and find their total weight \(A\). Then we can determine the unique integer \(j\in\{1,2,\dots, n\}\) such that the box \(j\) contain fake coins, while boxes \(j+1\), \(j+2\), \(\dots\), \(n\) contain all real coins. We prove this by induction on \(n-j\).
Assume that the weight of coins from the box \(i\) is \(x_i\). Then for each \(i\) we have \(x_i\in\{w,f\}\). If we assume that \(x_n=f\) then we have \(A=\sum \alpha_ix_i \leq \sum_{i=1}^{n-1}\alpha_i w+ \alpha_n\frac{M}N=B_n\). If we assume that \(x_n=w\) then we have \(A\geq \sum_{i=1}^{n-1}\alpha_i\cdot \frac{M-Lw}{N-L}+ \alpha_nw=A_n\). By our choice of \(\alpha_n\) we have that \(B_n < A_n\).
Now if we find out that \(A\leq B_n\) we can be sure that \(x_n=f\) because otherwise we must have \(A\geq A_n > B_n\) which contradicts the fact that \(B_n < A_n\). Similarly, if \(A\geq A_n\) we know that \(x_n=w\).
If it turned out that \(x_n=f\) then we found \(j=0\). Otherwise, we can repeat the same procedure for boxes \(1\), \(2\), \(\dots\), \(n-1\) whose total sum of weights is \(A-\alpha_nw\).
In such a way we arrive to the box \(j\) that contains the fake coins. We know the total mass of all coins in boxes \(1\), \(\dots\), \(j\), which is equal to \(\hat A=A-\alpha_nw-\alpha_{n-1}w-\cdots-\alpha_{j+1}w\). Then we have \(\hat A=\alpha_1x_1+\cdots + \alpha_{j-1}x_{j-1}+\alpha_j f \leq (\alpha_1+\cdots+\alpha_{j-1})w+\alpha_jf\) and \(\hat A\geq \alpha_j f\) which implies that \[\frac{\hat A}{\alpha_j}-\frac{\sum_{i=1}^{j-1}\alpha_i}{\alpha_j}\leq f\leq \frac{\hat A}{\alpha_j}.\] Thus the lemma is proved for \(\hat f=\frac{\hat A}{\alpha_j}\). The proof of the lemma is complete.
For each sequence \(\overrightarrow a\in\{0,1\}^n\) let us define \(\varphi(\overrightarrow a, f)= T_{\overrightarrow a}f+(N-T_{\overrightarrow a})w\).
If \(f\) and \(f^{\prime}\) are two real numbers smaller than \(w\), and \(\overrightarrow a\) and \(\overrightarrow b\) two sequences then we have:
\begin{eqnarray*}
\left|\varphi(\overrightarrow a, f)-\varphi(\overrightarrow b,f’)\right|&=&\left|T_{\overrightarrow a}(f-w)-T_{\overrightarrow b}(f’-w)
\right|\\
&=&\left|T_{\overrightarrow a}(f-w)-T_{\overrightarrow b}(f-w)+ T_{\overrightarrow b}(f-f’)
\right|\\&\geq& \left|T_{\overrightarrow a}-T_{\overrightarrow b}\right|\cdot |f-w|-T_{\overrightarrow b}|f-f’|\\
&\geq& 3\omega \cdot\left(w-\frac MN\right)-N\cdot |f-f’|.
\end{eqnarray*}
In the last inequality we used that \(w-f > w-\frac MN\) and \(|T_{\overrightarrow a}-T_{\overrightarrow b}|\geq 3\omega\).
It suffices to pick \(\varepsilon\) that satisfies \(\varepsilon < \frac {3\omega}N\cdot\left(w-\frac MN\right)\). Then we use lemma to find a value of \(\hat f\) that is within \(\varepsilon\) of \(f\), and then we check all the possible values of \(\varphi(\overrightarrow a, \hat f)\). The sequence \(\overrightarrow a\) for which \(|\varphi(\overrightarrow a, \hat f)-M|\) is minimal is the sequence of boxes with fake coins.