'Trotter Johnson permutation unranking. See [4] section 2.4.
Examples
>>> from sympy.combinatorics.permutations import Permutation
>>> Permutation.unrank_trotterjohnson(5, 10)
Permutation([0, 3, 1, 2, 4])
See Also
rank_trotterjohnson, next_trotterjohnson'

@classmethod
def unrank_trotterjohnson(cls, size, rank):

    perm = ([0] * size)
    r2 = 0
    n = ifac(size)
    pj = 1
    for j in range(2, (size + 1)):
        pj *= j
        r1 = ((rank * pj) // n)
        k = (r1 - (j * r2))
        if ((r2 % 2) == 0):
            for i in range((j - 1), ((j - k) - 1), (-1)):
                perm[i] = perm[(i - 1)]
            perm[((j - k) - 1)] = (j - 1)
        else:
            for i in range((j - 1), k, (-1)):
                perm[i] = perm[(i - 1)]
            perm[k] = (j - 1)
        r2 = r1
    return cls._af_new(perm)
