利用等差数列进行构造。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k; cin>>n>>k;
    vector<char> v(n + 1);
    int pos = 1;
    for(char c = 'a'; pos <= n; c =  (c - 'a' + 1) % 26 + 'a') {
        int now = 1;
        v[pos++] = c;
        while(k >= now) {
            v[pos++] = c;
            k -= now;
            now++;
        }
    }
    for(int i = 1; i <= n; ++i) cout<<v[i];
}