'This is a linear time unranking algorithm that does not
respect lexicographic order [3].
Examples
>>> from sympy.combinatorics.permutations import Permutation
>>> Permutation.print_cyclic = False
>>> Permutation.unrank_nonlex(4, 5)
Permutation([2, 0, 3, 1])
>>> Permutation.unrank_nonlex(4, -1)
Permutation([0, 1, 2, 3])
See Also
next_nonlex, rank_nonlex'

@classmethod
def unrank_nonlex(self, n, r):

    def _unrank1(n, r, a):
        if (n > 0):
            (a[(n - 1)], a[(r % n)]) = (a[(r % n)], a[(n - 1)])
            _unrank1((n - 1), (r // n), a)
    id_perm = list(range(n))
    n = int(n)
    r = (r % ifac(n))
    _unrank1(n, r, id_perm)
    return self._af_new(id_perm)
