https://programmers.co.kr/learn/courses/30/lessons/12936#
#include <string>
#include <vector>
#include <iostream>
using namespace std;
long long Factorial(long long n){
long long res =1;
for(int i=1;i<=n;i++){
res *= i;
}
return res;
}
vector<int> solution(int n, long long k) {
vector<int> answer;
vector<long long > num;
for(int i= 1;i<=n;i++){
num.push_back(i);
}
int div = n-1;
k--;
while(div != 0){
long long fdiv = Factorial(div);
answer.push_back(num[k/fdiv]);
num.erase(num.begin()+k/fdiv);
k = k%fdiv;
div--;
}
answer.push_back(num[0]);
return answer;
}
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> setAlign(int n, long long cnt)
{
vector<int> answer;
for(int i=1;i<=n; i++) answer.push_back(i);
long long i=1;
do {
if(cnt==i++) break;
}while(next_permutation(answer.begin(),answer.end()));
return answer;
}
int main()
{
int testn = 3;
long long testcnt = 5;
vector<int> testAnswer = setAlign(testn,testcnt);
// 아래는 테스트로 출력해 보기 위한 코드입니다.
for(int i=0; i< testAnswer.size(); i++)
{
cout << testAnswer[i] << " ";
}
}