stringgetPermutation(int n,int k) { vector<int> factorials = {1,1,2,6,24,120,720,5040,40320}; vector<int>nums(n,0);iota(std::begin(nums), std::end(nums),1); string ret; k --; // 从第 0 个开始for(int i = n -1; i >=0; i --){auto it =nums.begin() + k /factorials[i]; ret += ('0'+*it);nums.erase(it); k %=factorials[i]; }return ret;}