#include<bits/stdc++.h> //#define endl "\n" using namespace std; unsigned long long n, k, dp[1000010], inf = 1e18; bool jest; vector< char > ans; int main() { ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); cin>>n>>k; inf *= 4; inf += 9; for( int a = 1; a <= n; a++ ) { if( dp[a-1] == inf )dp[a] = inf; else { dp[a] = 2*dp[a-1] + 3; if( dp[a] >= inf )dp[a] = inf; } } // cout<<"ok"<<endl; if( k > dp[n] ) { cout<<"NIE"; return 0; } for( int a = n; a >= 1; a-- ) { // cout<<k<<endl; if( a == n ) { if( 3*k <= dp[a] )ans.push_back( 'a' ); else if( 3*k <= 2*dp[a] ) { ans.push_back( 'b' ); k -= (dp[a]/3); } else { ans.push_back( 'c' ); k -= (2*(dp[a]/3)); } continue; } if( k == 1 )break; k--; if( 3*k <= dp[a] ) { //cout<<"tu1"<<endl; if( ans.back() == 'a' )ans.push_back( 'b' ); else ans.push_back( 'a' ); } else { //cout<<"tu2"<<endl; if( ans.back() == 'c' )ans.push_back( 'b' ); else ans.push_back( 'c' ); k -= (dp[a]/3); } } for( int a = 0; a < ans.size(); a++ )cout<<ans[a]; 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #include<bits/stdc++.h> //#define endl "\n" using namespace std; unsigned long long n, k, dp[1000010], inf = 1e18; bool jest; vector< char > ans; int main() { ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); cin>>n>>k; inf *= 4; inf += 9; for( int a = 1; a <= n; a++ ) { if( dp[a-1] == inf )dp[a] = inf; else { dp[a] = 2*dp[a-1] + 3; if( dp[a] >= inf )dp[a] = inf; } } // cout<<"ok"<<endl; if( k > dp[n] ) { cout<<"NIE"; return 0; } for( int a = n; a >= 1; a-- ) { // cout<<k<<endl; if( a == n ) { if( 3*k <= dp[a] )ans.push_back( 'a' ); else if( 3*k <= 2*dp[a] ) { ans.push_back( 'b' ); k -= (dp[a]/3); } else { ans.push_back( 'c' ); k -= (2*(dp[a]/3)); } continue; } if( k == 1 )break; k--; if( 3*k <= dp[a] ) { //cout<<"tu1"<<endl; if( ans.back() == 'a' )ans.push_back( 'b' ); else ans.push_back( 'a' ); } else { //cout<<"tu2"<<endl; if( ans.back() == 'c' )ans.push_back( 'b' ); else ans.push_back( 'c' ); k -= (dp[a]/3); } } for( int a = 0; a < ans.size(); a++ )cout<<ans[a]; return 0; } |