There is a set of control weights, each of them weighs a non-integer number of grams. Any
integer weight from $1$ g to $40$ g can be balanced by some of these weights (the control
weights are on one balance pan, and the measured weight on the other pan).What is the
least possible number of the control weights?

[i](Alexandr Shapovalov)[/i]
To solve this problem, we need to find the least number of control weights such that any integer weight from 1 g to 40 g can be balanced using these weights. The control weights are placed on one pan of the balance, and the measured weight is placed on the other pan.

1. **Understanding the Problem:**
   - We need to balance any integer weight from 1 g to 40 g.
   - The control weights are non-integer and can be placed on one pan of the balance.
   - The measured weight is placed on the other pan.

2. **Binary Representation Insight:**
   - The initial solution suggests using the binary representation of 40, which is \(101000_2\).
   - This implies that any integer from 1 to 40 can be represented using at most 6 bits.
   - The weights corresponding to these bits are \(1, 2, 4, 8, 16, 32\).

3. **Verification of the Binary Approach:**
   - The binary approach works for representing numbers, but it does not directly apply to balancing weights on a balance scale.
   - We need to consider the possibility of placing weights on both pans of the balance.

4. **Using Ternary (Base-3) Representation:**
   - In a balance problem, we can use weights on both sides of the balance. This suggests using a ternary (base-3) system.
   - In a ternary system, each digit can be -1, 0, or 1, representing placing a weight on the left pan, not using the weight, or placing it on the right pan, respectively.

5. **Finding the Minimum Number of Weights:**
   - We need to find the smallest set of weights such that any integer from 1 to 40 can be balanced.
   - The weights in a ternary system are powers of 3: \(3^0, 3^1, 3^2, \ldots\).

6. **Calculating the Required Weights:**
   - The maximum weight we need to balance is 40 g.
   - We need to find the smallest \(n\) such that the sum of the series \(3^0 + 3^1 + 3^2 + \ldots + 3^n \geq 40\).

   \[
   \text{Sum of the series} = \frac{3^{n+1} - 1}{2}
   \]

   - We need to solve for \(n\):

   \[
   \frac{3^{n+1} - 1}{2} \geq 40
   \]

   \[
   3^{n+1} - 1 \geq 80
   \]

   \[
   3^{n+1} \geq 81
   \]

   \[
   n+1 \geq 4
   \]

   \[
   n \geq 3
   \]

   - Therefore, we need weights \(3^0, 3^1, 3^2, 3^3\), which are \(1, 3, 9, 27\).

7. **Verification:**
   - With weights \(1, 3, 9, 27\), we can balance any weight from 1 to 40 g.
   - For example:
     - To balance 1 g: use \(1\) on the left pan.
     - To balance 2 g: use \(3\) on the left pan and \(1\) on the right pan.
     - To balance 40 g: use \(27 + 9 + 3 + 1\) on the left pan.

Thus, the least possible number of control weights is 4.

The final answer is \(\boxed{4}\).