2

In the equation a * b = c, given a, how can I find the lowest integer c provided that:

  • a is a terminating decimal
  • b is an integer

Here is an example:

  • a = 0.2525, b = 400, c = 101

I realize that I can multiply the decimal by 10^(decimal length) for primes, but how do I find the answer for non-primes? Am I overthinking this?

jsejcksn
  • 123

1 Answers1

1

Simply write $a=\dfrac{c}{b}$ as an irreductible fraction, and this will give you the lowest integer $c$ and $b$.

Example: $a=0.2525=\dfrac{2525}{10000}=\dfrac{101}{400}$ yields $b=400$ and $c=101$. $c$ is minimal because $b,c$ are coprime integers.

anderstood
  • 3,504
  • But that's not what I'm asking. I'm asking how to determine what the value of C is given A in my equation. How do I get to the reduction? – jsejcksn Jun 12 '16 at 23:37
  • 1
    @JesseJackson That's what I am answering. I added an example. Given $a$, you get $c$ (and also of course $b$ which is determined by $a$ and $c$). – anderstood Jun 12 '16 at 23:39
  • @anderstood: I understand OP to mean, what is the algorithm to reduce a given fraction $a/b$ to lowest terms. OP: You need an algorithm for finding the GCD of two integers; you then divide both numerator and denominator by the GCD. Euclid's algorithm works well. – Brian Tung Jun 12 '16 at 23:40
  • Perfect. That is what I am looking for! Thanks. – jsejcksn Jun 12 '16 at 23:42