Search code examples
.netalgorithmmath

How to calculate least common denominator


I could not find anything because of my English perhaps. I want to find the smallest dividing value of several numbers. In German it is called: http://de.wikipedia.org/wiki/Hauptnenner I want to know how to do this in .Net because I cannot believe that this question is new and have not found a solution except to do it like on paper to count the "2 dividers and 3 dividers".

Would be great to get any advice.

Regards


Solution

  • The website already tells you how to do it: Find the least common multiple for the set of all denominators. You can exploit the relation between least common multiple and greatest common divisor (see Wikipedia) and simply use the Euclidean algorithm (also available on Wikipedia).

    Schau nach, wie du den ggT (groessten gemeinsamen Teiler berechnest -> Euklids Algorithmus). Danach kannst du den Hauptnenner aus dem kgV der Nenner berechnen.