public String getPermutation(int n, int k) {
        String s = new String();
        --k;
        boolean[] used = new boolean[n];

        for (int i = n - 1; i > 0; --i) {
            int factor = factorial(i), tmp = k / factor, j = 0;
            while (true) {
                if (used[j]) {
                    ++j;
                    continue;
                }
                else {
                    if (tmp == 0) break;
                    --tmp;
                    ++j;
                }
            }
            used[j] = true;
            s += j + 1;
            k %= factor;
        }

        for (int i = 0; i < n; ++i)
            if (!used[i]) {
                s += i + 1;
                break;
            }

        return s;

        /*//会超时
        int[] num = new int[n];
        for (int i = 0; i < n; i++)
            num[i] = i + 1;
        for (int i = 0; i < k - 1; i++)
            nextPermutation(num);
        String s = new String();
        for (int i : num)
            s += i;
        return s;*/
    }