Now that we have learned a bit about logarithms in base 10, we should understand
that we can take a logarithm to any base. Let's recall the definition of a logarithm.
Namely, if 10 ^ x = y then log_10(y) = x. However, it shouldn't come as a
surprise that we could replace 10 with any number to yield the general statement
if b ^ x = y then log_b(y) = x.
$$ \small \space $$
The plotted graphs of y = log_2(x), y = log_3(x), and y = log_10(x).
$$ \tiny \space $$
Thankfully, there is a simple relation which can be utilized for calculating logarithms in any base.
$$ \large \log_{b_{0}}(x) = \frac{\log_{b_{1}}(x)}{\log_{b_{1}}(b_{0})} $$
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 $$
Using the above relationships and given values above, approximate the logarithms
of the following numbers in the indicated bases.
Please use the method of approximation
using known values as described in this problem,
instead of
calculating the answers directly using a calculator or computer. In cases where
they 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 two space-separated values in the format
Y B.
Answer
Should consist of Q space-separated values, corresponding to the approximated
base-B logarithm of each given integer Y.
Round all answers to the nearest 1e-6.
Example
input data:
4
6
504
32400
5080320
answer:
0.778151 2.70243 4.510544 6.70589