Ankit_132

D

Jul 11th, 2023
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.     int N = 1e6 + 1;
  13.     vector<vector<int>> div(N);
  14.  
  15.     for(int i=1; i<N; i++)
  16.     {
  17.         for(int j=2*i; j<N; j+=i)
  18.             div[j].pb(i);
  19.     }
  20.  
  21.     vector<bool> pos(26);
  22.  
  23.     _test
  24.     {
  25.         int n;
  26.         cin>>n;
  27.  
  28.         string ans;
  29.         ans.pb('a');
  30.  
  31.         for(int i=1, f; i<n; i++)
  32.         {
  33.             fill(pos.begin(), pos.end(), true);
  34.             f = 1;
  35.  
  36.             for(auto e: div[n])
  37.             {
  38.                 if((int)(ans.size())-e >= 0)
  39.                     pos[ans[ans.size()-e]-'a'] = false;
  40.             }
  41.  
  42.             for(int j=0; j<26; j++)
  43.             {
  44.                 if(pos[j])
  45.                 {
  46.                     f = 0;
  47.                     ans.pb('a'+j);
  48.                     break;
  49.                 }
  50.             }
  51.         }
  52.  
  53.         cout<<ans<<"\n";
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment