We are given that it takes a butterfly egg 120 days to become a butterfly.
Let's assume that the butterfly spends y days as a larva and z days in a cocoon.
According to the given information, y + z = 120.
We are also given that each butterfly spends x times as much time as a larva as in a cocoon, so y = xz.
Substituting y = xz into the first equation, we get: xz + z = 120.
Simplifying, we get: z(x + 1) = 120.
We are given that each butterfly spends 30 days in a cocoon, so we can write: z = 30.
Substituting z = 30 into the equation z(x + 1) = 120, we get: 30(x + 1) = 120.
Dividing both sides by 30, we get: x + 1 = 4.
Subtracting 1 from both sides, we get: x = 3.
The value of x is 3.
#### 3
The answer is: 3
Below is a math problem. Provide a detailed, step-by-step solution.

### Problem:
It takes a butterfly egg 120 days to become a butterfly. If each butterfly spends x times as much time as a larva as in a cocoon, how long does each butterfly spend in a cocoon?
If we know the answer to the above question is 30, what is the value of unknown variable x?

### Answer:
