```
string getPermutation(int n, int k) {
vector<int> used(n);
k--;
int total = 1;
for (int i = 1; i <= n; i++)
total *= i;
string result(n, ' ');
for (int i = 0; i < n; i++) {
total /= n - i;
int index = k / total, j = 0;
k %= total;
while (used[j] == 1 || index--)
j++;
used[j] = 1;
result[i] = '1' + j;
}
return result;
}
```