lcm Function

public pure function lcm(i, j)

LCM. based on code from NCAR Command Language

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(in) :: i
integer(kind=ip), intent(in) :: j

Return Value integer(kind=ip)


Source Code

    pure integer(ip) function lcm(i,j)
        integer(ip),intent(in) :: i,j
        integer(ip) :: rem,m,n
        m=abs(i)
        n=abs(j)
        lcm=0
        if (m<=0 .or. n<=0) return
        do
            rem=mod(m,n)
            if (rem<=0) exit
            m=n
            n=rem
        end do
        lcm=abs(i*j/n)
    end function lcm