public static String getPerm (int n, int k) {//AC
    	//form the list
    	ArrayList<Integer> ret = new ArrayList<Integer>();

    	ArrayList<Integer> ls = new ArrayList<Integer>();
    	for (int i = 0; i < n; ++i) {
    		ls.add(i+1);
    	}
    	
    	int rem = k-1;
    	int denom = factorial(ls.size()-1);
    	int div = rem / denom;
    	rem = rem % denom;
    	for (int i = 0; i < n; ++i) {
    		ret.add(ls.get(div));
    		ls.remove(div);
    		denom = factorial(ls.size()-1);
    		div = rem / denom;
    		rem = rem % denom;
    	}
    	System.out.println(ret);
    	String res = "";
    	for (int i = 0; i < ret.size(); ++i) {
    		res += ret.get(i);
    	}
    	return res;
    	
    }