module SpecialFunctionLib
use constants
implicit none

    private
    public:: factorial
    
    
!-------------------------------------------
    interface factorial
        module procedure::  factorial_1n
        module procedure::  factorial_kn
    end interface factorial

contains

    pure function factorial_1n(n) result(factorial)
    integer(ip),intent(in)::    n
    integer(ip)::               factorial,i
        factorial = 1
        do i=1,n
            factorial = factorial*i
        enddo
    end function factorial_1n
    
    pure function factorial_kn(k,n) result(factorial)
    integer(ip),intent(in)::    k,n
    integer(ip)::               factorial,i
        factorial = 1
        do i=k,n
            factorial = factorial*i
        enddo
    end function factorial_kn
    
end module SpecialFunctionLib