I haven't found an answer to this anywhere. Excluding brute force, given a rational $q$ in its decimal form ($1.47$, for example), is there a good algorithm to find integers $m$ and $n$ such that $\frac m n = q$? Thank you.
Given a rational, how to find the integers whose quotient it is?
292 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 3 best solutions below
On
If $q$ is in decimal form well yes, there's the whole "if $q$ is not periodic then it is $q$ without . divided by $10^n$, if it's periodic do this and that" (if you meant this comment and I'll write it all)
On
Here's the technique I learned in grade school: examine $q$ to determine its finite and repeating parts: $q = a{.}f\bar{r}$, where $a$ is the integer part, and $f$ and $r$ are the finite and repeating parts. Say $f$ has length $k$ and $r$ has length $l$, so that after multiplying $q$ by $10^k$, we get $x = 10^k q = af{.}\bar{r}$, and multiplying that by $10^l$ we get $y = 10^{k + l} q = afr.\bar{r}$. Note that $y - x = afr - af$ as well as $y - x = 10^k(10^l -1)q$. So solving for $q$, we get $q = (afr - af)/ 10^k(10^l -1)$.
Note that $af$ and $afr$ are the concatenations of $a$, $f$, and $r$, not their product; i.e. $af = 10^k a + f$ and $afr = 10^l af + r$.
If $q$ is given as a decimal, then as $q$ is rational, there are two possibilities:
If $q$ has a finite decimal representation, then $10^nq$ is an integer, call it $m$, for some choice of $n$ (in particular, $n$ is the number of digits after the decimal). In that case, $q = \dfrac{m}{n}$.
If $q$ has a repeating decimal expansion, write $q$ as $r + s$ where $r$ has finite decimal representation and $s$ is the 'repeating part'.
Using the first part, you can write $r$ as a fraction, so you just need to know how to write $s$ as a fraction. First, set $s' = 10^ts$ where $t$ is the number of zeroes between the decimal point and the number which repeats.
Now let $l$ denote the number which repeats in $s'$, which may have many digits.
Now there is some $k$ such that $10^ks$ has integer part $l$; in particular, $k$ is the number of digits in $l$.
Now note that $10^ks' - l = s'$.
Therefore, $(10^k - 1)s' = l$ so $s' = \dfrac{l}{10^k-1}$.
Once you have $s'$ as a fraction, you can easily determine $s$ as a fraction by using the fact that $s = 10^{-t}s'$. Together with the fraction for $r$, you can then determine the fraction for your original $q$.