def unlinearize_term(index, n_orbitals):
    """Function to return integer index of term indices.

    Args:
        index(int): The index of the term.
        n_orbitals(int): The number of orbitals in the simulation.

    Returns:
        term(tuple): The term indices of a one- or two-body FermionOperator.
    """
    # Handle identity term.
    if not index:
        return (())
    elif (0 < index < 1 + n_orbitals ** 2):
        # Handle one-body terms.
        shift = 1
        new_index = index - shift
        q = new_index // n_orbitals
        p = new_index - q * n_orbitals
        assert index == shift + p + q * n_orbitals
        return ((p, 1), (q, 0))
    else:
        # Handle two-body terms.
        shift = 1 + n_orbitals ** 2
        new_index = index - shift
        s = new_index // n_orbitals ** 3
        r = (new_index - s * n_orbitals ** 3) // n_orbitals ** 2
        q = (new_index - s * n_orbitals ** 3 -
             r * n_orbitals ** 2) // n_orbitals
        p = (new_index - q * n_orbitals -
             r * n_orbitals ** 2 - s * n_orbitals ** 3)
        assert index == (shift + p + q * n_orbitals +
                         r * n_orbitals ** 2 + s * n_orbitals ** 3)
        return ((p, 1), (q, 1), (r, 0), (s, 0))