给定一个完全由小写英文字母组成的字符串等差递增序列,该序列中的每个字符串的长度固定为 L,从 L 个 a 开始,以 1 为步长递增。例如当 L 为 3 时,序列为 { aaa, aab, aac, ..., aaz, aba, abb, ..., abz, ..., zzz }。这个序列的倒数第27个字符串就是 zyz。对于任意给定的 L,本题要求你给出对应序列倒数第 N 个字符串。
输入格式:
输入在一行中给出两个正整数 L(2 ≤ L ≤ 6)和 N(≤105)。
输出格式:
在一行中输出对应序列倒数第 N 个字符串。题目保证这个字符串是存在的。
输入样例:
3 7417
输出样例:
pat
类似进制转换
string intToA(int n,int radix)
{
string ans="";
do{
int t=n%radix;
if(t>=0&&t<=9)
ans+=t+'0';
else
ans+=t-10+'a';
n/=radix;
}while(n!=0);
reverse(ans.begin(),ans.end());//**反转输出**//
return ans;
}
string ans="";
ll LL=pow(26,L);//获得radix,类似于是一个LL进制的数
ll x=LL-N;//倒数第N个,正数第x个
for(int i=L-1;i>=0;i--)
{
ll t=pow(26,i);//第i+1位的radix
ans+=(x/t)+'a';//第i+1的数
x=x%t;
}
cout<<ans<<endl;
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f;
priority_queue<int,vector<int>,greater<int>>q;
const int mod=10e9+7;
int main()
{
int L,N;
cin>>L>>N;
string ans="";
ll LL=pow(26,L);
ll x=LL-N;
for(int i=L-1;i>=0;i--)
{
ll t=pow(26,i);
ans+=(x/t)+'a';
x=x%t;
}
cout<<ans<<endl;
return 0;
}