GCD-LCM ======= Save all functions into the same file named ``gcdlcm.py``. #. Write the funcion :py:func:`gcd` that takes two positive integers *a* and *b*, and returns its greatest common divisor. Proposed method: using the following sequence *min(a,b)*, *min(a,b)-1, ..., 2, 1*, the first element of this sequence that divides both *a* and *b* is its greatest common divisor. Examples: .. literalinclude:: gcd-1.txt :language: python3 :lines: 2- .. note:: More tests are provided in file :download:`gcd-1.txt` #. Write the function :py:func:`gcd_euclides_1` that takes two positive integers *a* and *b*, and returns its greatest common divisor. Use the Euclides method based on the following *gcd* properties: - :math:`gcd(a,b)=gcd(b,a)` - if :math:`a>b` then :math:`gcd(a,b)=gcd(a-b,b)` - if :math:`b>a` then :math:`gcd(a,b)=gcd(a,b-a)` - :math:`gcd(a,a)=a` Examples: :math:`gcd(5,15)=gcd(5,10)=gcd(5,5)=5` .. literalinclude:: gcd-2.txt :language: python3 :lines: 2- .. note:: More tests are provided in file :download:`gcd-2.txt ` #. Write the function :py:func:`gcd_euclides_2` that takes two positive integers *a* and *b*, and returns its greatest common divisor. Use the `Euclides method `__ based on the following *gcd* properties: - if :math:`a=c\times b+r`, then :math:`gcd(a,b)=gcd(b,r)` - :math:`gcd(a, 0)= a` Examples: :math:`gcd(567,28)=gcd(28,7)=gcd(7,0)=7` .. literalinclude:: gcd-3.txt :language: python3 :lines: 2- .. note:: More tests are provided in file :download:`gcd-3.txt ` #. Write the function :py:func:`lcm` that takes two positive integers *a* and *b*, and returns its `least common multiple `__ . Use some of the previous functions. Examples: .. literalinclude:: lcm.txt :language: python3 :lines: 2- .. note:: More tests are provided in file :download:`lcm.txt ` .. rubric:: Solution A solution of these functions is provided in the :download:`gcdlcm.py ` file.