#include <iostream> using namespace std; int potega( int a, int wyk ) { if ( wyk == 0 ) return 1; if ( wyk %2 == 1 ) { return potega( a, wyk - 1 ) * a; } int t = potega( a, wyk /2 ); return t*t; } int tab[2000000]; int main() { int n, t; cin>>n>>t; int l = potega( 2, n ); t %= 2; for ( int i = 0; i < l; i++ ) { cin>>tab[i]; } if ( t == 0 ) { for ( int i = 0; i < l; i++ ) { cout<<tab[i]<<" "; } } else { for ( int i = l - 1; i >= 0; i-- ) { cout<<tab[i]<<" "; } } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <iostream> using namespace std; int potega( int a, int wyk ) { if ( wyk == 0 ) return 1; if ( wyk %2 == 1 ) { return potega( a, wyk - 1 ) * a; } int t = potega( a, wyk /2 ); return t*t; } int tab[2000000]; int main() { int n, t; cin>>n>>t; int l = potega( 2, n ); t %= 2; for ( int i = 0; i < l; i++ ) { cin>>tab[i]; } if ( t == 0 ) { for ( int i = 0; i < l; i++ ) { cout<<tab[i]<<" "; } } else { for ( int i = l - 1; i >= 0; i-- ) { cout<<tab[i]<<" "; } } return 0; } |