CEMC Banner

Problem of the Week
Problem D and Solution
Another Program

Problem

To practice her programming skills, Tessa wrote a program that takes an input number, squares it, adds a constant value, multiplies the result by another constant value, and then outputs the result.

When the input is \(8\), the output is \(204\). When the input is \(3\), the output is \(39\).

What is the output when the input is \(5\)?

Solution

Let the first constant value be \(k\) and the second constant value be \(p\). Then Tessa’s program takes an input number, squares it, adds \(k\), multiplies the result by \(p\), and then outputs the result.

Since an input of \(8\) gives an output of \(204\), \[\begin{align} (8^2+k)\times p &= 204\\ p &= \frac{204}{64+k} \tag{1} \end{align}\] Similarly, since an input of \(3\) gives an output of \(39\), \[\begin{align} (3^2+k)\times p &= 39\\ p &= \frac{39}{9+k} \tag{2} \end{align}\] From equations \((1)\) and \((2)\), we can conclude the following. \[\begin{align} \frac{204}{64+k} &= \frac{39}{9+k}\\ 204(9+k) &= 39(64+k)\\ 1836 + 204k &= 2496 + 39k\\ 165k &= 660\\ k &= \frac{660}{165} = 4 \end{align}\] Then \(p = \dfrac{39}{9+k} = \dfrac{39}{9+4} = 3\).

Now that we have determined the values of \(k\) and \(p\), we can determine the output when the input is \(5\). \[(5^2+4) \times 3 = 29 \times 3 = 87\]

Thus, the output is \(87\) when the input is \(5\).