Logarithms

Problem #17

Tags: computing instructional

Who solved this?

Previous:The Bell Curve Next:Arbitrary Base Logarithms


The logarithm is one of the final "basic" mathematical operations we will observe. However while the initial concept of the logarithm may appear simple, the study of logarithms has profound implications, and was crucial in laying the foundation for many early concepts in calculus. To put it simply, if 10 ^ x = y then log_10(y) = x. Written neatly...

$$ \large \log_{10}(y) = x $$

We would say that the logarithm here is in "base 10". We might be able to easily figure out that log_10(10) = 1, log_10(100) = 2, log_10(100000) = 5, and log_10(1) = 0.

$$ \small \space $$

log10x

The plotted graph of y = log_10(x).

$$ \tiny \space $$

But it's still not apparent how we would calculate the value of log_10(6), for example. Historically, this would be done using a small table of pre-determined values and utilizing some clever properties of logarithms to approximate the solution. These properties are:

$$ \large \log_b \left( n \cdot m \right) = \log_b \left( n \right) + \log_b \left( m \right) $$ $$ \large \log_b \left( \frac{n}{m} \right) = \log_b \left( n \right) - \log_b \left( m \right) $$ $$ \large \log_b \left( n^m \right) = m \cdot \log_b \left( n \right) $$

And here are a few common values:

$$ \large \log_{10}(2) \approx 0.301030 $$ $$ \large \log_{10}(3) \approx 0.477121 $$ $$ \large \log_{10}(5) \approx 0.698970 $$ $$ \large \log_{10}(7) \approx 0.845098 $$

Problem Statement

Using the above relationships and values provided above, approximate the base-10 logarithms of the given testcases.
Testcases will be chosen to ensure that an approximation is possible using only the provided values.
Please use the above approximation method, rather than using a built-in function on a computer or calculator. In cases where the answers would be different due to rounding error, the approximated answer will be accepted rather than the exact one.

Input Data
First line will be Q, the quantity of testcases.
Q lines will then follow, each with a single integer.

Answer
Should consist of Q space-separated values, corresponding to the approximated base-10 logarithm of each given integer. Report the approximation to 6 decimal places.

Example

input data:
4
6
504
32400
5080320

answer:
0.778151 2.70243 4.510544 6.70589
You need to login to get test data and submit solution.