public static int[] permutationByNumber(int n, long number) {
        long[] fact = new long[n];
        fact[0] = 1;
        for (int i = 1; i < n; i++) {
            fact[i] = i * fact[i - 1];
        }
        int[] p = new int[n];
        int[] free = new int[n];
        for (int i = 0; i < n; i++) {
            free[i] = i;
        }
        for (int i = 0; i < n; i++) {
            int pos = (int) (number / fact[n - 1 - i]);
            p[i] = free[pos];
            System.arraycopy(free, pos + 1, free, pos, n - 1 - pos);
            number %= fact[n - 1 - i];
        }
        return p;
    }