lcm Function

public elemental function lcm(a, b)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: a
integer, intent(in) :: b

Return Value integer


Source Code

   ELEMENTAL FUNCTION lcm(a, b)
      INTEGER, INTENT(IN)                                :: a, b
      INTEGER                                            :: lcm

      INTEGER                                            :: tmp

      tmp = gcd(a, b)
      IF (tmp == 0) THEN
         lcm = 0
      ELSE
         ! could still overflow if the true lcm is larger than maxint
         lcm = ABS((a/tmp)*b)
      END IF
   END FUNCTION lcm