def hund_case_b_landau_g_factor(n, j, s, l, gs, gl):
    """ Hund case B Landau g-factor

    .. math::
        g = g_s \\frac{J(J+1) + S(S+1) - N(N+1)}{2J(J+1)} +
        g_l \\Lambda \\frac{J(J+1) - S(S+1) + N(N+1)}{2JN(J+1)(N+1)}

    Parameters:
        n (float): N of level

        j (float): J of level

        l (float): Lambda of level

        s (float): S of level

        gs (float): relativistic spin factor of molecule

        gl (float): relativistic orbital factor of molecule

    Returns:
        g (float): Landau g-factor for Hund case B
    """
    if n != 0:
        return gs * (j * (j+1) + s * (s+1) - n * (n+1)) / (2 * j * (j + 1)) + \
            l * gl * (j * (j+1) - s * (s+1) + n * (n+1)) / (2 * j * n * (j + 1) * (n + 1))
    else:
        return gs * (j * (j+1) + s * (s+1) - n * (n+1)) / (2 * j * (j + 1))