public String getPermutation(int n, int k) {
        if (n==1) return "1";

        String rs = "";
        if(k==1) { 
            for (int i=1; i<=n; i++){
                rs += i;
            }
            return rs;
        }
        k = k - 1;

        int[] product = new int[8];
        product[0] = 1;
        for(int i=1; i<8; i++){
            product[i] = (i+1) * product[i-1];
        }
        HashSet<Integer> set = new HashSet<Integer>();
        for (int i=1; i<=n; i++) set.add(i);

        for(int i=n-1; i>=0; i--){
            int digit;
            if(i>0) {
                digit = k/product[i-1];
                k = k%product[i-1];
            }
            else digit = 0;
            //System.out.println("digit:"+digit);
            //System.out.println(set);
            int j = 0;
            while (digit>=0){
                j++;
                if(set.contains(j)){
                    digit--;
                }
            }
            rs += j;
            set.remove(j);
        }
        return rs;
        
    }