goofy ahh solution (n or n ** 2 ? )
Intuitionusing 'scoping'. greedily generate prefix, for each MSB, if k in range, we reduce k and go into the range. use double in C++. At first I thought need t
# Intuition
using 'scoping'. greedily generate prefix, for each MSB, if k in range, we reduce k and go into the range. use double in C++. At first I thought need to use log comparison, turns out it leads to precision nightmare.

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    double logF(int s){
        double res = 1;
        for(int i = 1; i <= s; i++){
            res *= i;
        }
        return res;
    }
    vector<int> permute(int n, long long k) {
        vector<int> res;
        vector<int> visited(n,0);
        int ep = n/2;
        int op = n - ep;
        int its = 0;
        double l = logF(op)*logF(ep);
        if(n%2 == 0){l*=2;}
        
        if(k>l){return {};}
        while(k > 0){
            
            int rl = res.size();
            if(rl == n){break;}
            int delta = 2;
            if(rl == 0){
                if(n%2 == 0)delta = 1;
            }
            
            int start = 1;
            if(rl > 0){
                start = res.back()%2 == 1 ? 2 : 1;
            }
            
            for(int i = start; i <= n ; i+=delta){
                if(visited[i-1] == 0){
                    int cep = rl/2;
                    int cop = rl-cep;
                    if(rl%2 == 1){cep += 1;}
                    else{cop += 1;}
                    
                    double lf = logF(op-cop)*logF(ep-cep);
                    
                    if(k > lf){
                        k -= lf;
                    }
                    else{
                        visited[i-1] = 1;
                        res.push_back(i);
                        break;
                    }
                }
            }
            its ++ ;
           
        }
        return res;
    }
};
```
['C++']