We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
C++ Accepted Solution. Using Factorial Number System
#include<bits/stdc++.h>usingnamespacestd;#define ll long long#define lb endl#define mod 1000000007llfact(lln){if(n<=1)return1;returnfact(n-1)*n;}voidsolve(){lln;cin>>n;--n;vector<char>alpha={'a','b','c','d','e','f','g','h','i','j','k','l','m'};stringans="";for(inti=12;i>=0;--i){llfactorial=fact(i);llx=(n)/factorial;ans+=alpha[x];n-=factorial*x;alpha.erase(alpha.begin()+x);}cout<<ans<<endl;}intmain(){OJ;ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);intt;cin>>t;while(t--){solve();}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #24: Lexicographic permutations
You are viewing a single comment's thread. Return to all comments →
C++ Accepted Solution. Using Factorial Number System