As a complement to the opposite solutions, let me elaborate the thought of utilizing base-3 illustration in particulars. Consider any optimistic integer $m$ that may be represented in base 3 with $n$ digits as follows:

$$

m=sum_{i=0}^{n-1}a_icdot 3^{i}, quadquad a_iin{0,1,2}

$$

Our purpose is to signify it utilizing $a_iin{-1,0,1}$. This may be carried out as follows

$$

m^*=m-sum

_{i=0}^{n-1}3^i=sum_{i=0}^{n-1}(a_i-1)cdot 3^{i}=sum_{i=0}^{n-1}c_icdot 3^{i}, quadquad c_iin{-1,0,1}

$$

Note

$$

sum

_{i=0}^{n-1}3^i=frac{1-3^n}{1-3}=frac{3^n-1}{2}

$$

Since

$$

min{kinmathbb{Z}:kin[0,3^n-1]}

$$

we have now

$$

m^*inleft{kinmathbb{Z}:kinleft[-frac{3^n-1}{2},frac{3^n-1}{2}right]proper}

$$

In different phrases, any integer between $-frac{3^n-1}{2}$ and $frac{3^n-1}{2}$ may be represented in base 3 with $n$ digits the place the digits may be $-1$, 0, or $1$.

Then, given $m^*$, we are able to discover the smallest $n$ such that it may be represented as above. If $m^*>0$, then, we’d like

$$

m^*leqfrac{3^n-1}{2}Rightarrow ngeqlog_3(2m^*+1)

$$

So the smallest $n$ is $lceil log_3(2m^*+1) rceil$.

**Back to the issue**, to “weigh” any integer, we are able to first determine the smallest $n$ such that the integer is within the vary. Since $m^*=40$, we have now $n=lceil log_3(2times 40+1) rceil=4$. To receive the mixture of weights and their positions, we are able to signify the goal integer utilizing base 3 with ${-1,0,1}$. Then, for every digit (weight), whether it is $-1$, then put it on the identical facet because the goal integer; whether it is 0, then don’t use it; whether it is 1, then put it on the opposite facet of the size.

**Extension**. The above framework works provided that every weight can be utilized solely as soon as (no additional ones). Suppose that the variety of every weight is 2. Then, the query turns into tips on how to signify an integer in base 5 the place every digit may be $-2$, $-1$, $0$, $1$, and $2$. In this case, to map ${0,1,2,3,4}$ to ${-2,-1,0,1,2}$, we subtract $sum_{i=0}^{n-1}2cdot 5^{i}$. Then, the vary for $m^*$ turns into

$$

-frac{5^n-1}{2}leq m^* leqfrac{5^n-1}{2}

$$

The identical concept may be generalized in different comparable issues.