Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<string>
- #include<vector>
- #include<set>
- #include<map>
- #include<queue>
- #include<iterator>
- #include<algorithm>
- using namespace std;
- bool bi[1021];
- int ar[1021];
- int main(){
- /*freopen("i_suck.in","r",stdin);
- freopen("i_suck.out","w",stdout);*/
- long int a,b,c,d,e,x,y,z,n,k;
- while(scanf("%ld %ld",&n,&k)==1){
- for(a=0;a<=n;a++) bi[a]=0;
- for(a=1;a<n;a++){
- z=n-a;
- x=1;
- for(b=1;b<=z;b++) x=x*b;
- bool wi; wi=false;
- if(x>k){ continue; }
- for(b=1;b<=z+1;b++)
- if(x*b>=k){
- ar[a]=b;
- k=k-x*(b-1); if(k==1) k=0; break;
- }
- }
- bool zi;
- zi=false;
- for(a=1;a<=n;a++){
- if(ar[a]==0){ for(c=1;c<=n;c++) if(!bi[c]){ if(zi) cout<<" "; cout<<c; bi[c]=1; zi=true; break; } }
- if(ar[a]){ e=0;
- for(c=1;c<=n;c++){
- if(!bi[c]) e++;
- if(e>=ar[a]){ if(zi) cout<<" "; cout<<c; bi[c]=1; break; }
- }
- }
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement