➤ Problem Link : 1328B. K
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair int main() { int t; cin>>t; while(t--) { ll n,k; cin>>n>>k; ll ind=2*k; ll val=sqrt(ind); if(val*(val+1) > ind ) val--; int v=k-((val)*(val+1))/2; if(v==0) { v=val-1; } else { val++; v--; } // cout<<val<<" "<<v<<endl; string s(n,'a'); s[n-val-1]='b'; s[n-1-v]='b'; cout<<s<<endl; } }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!