CF1328B.K-th Beautiful String
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For the given integer n ( n>2 ) let's write down all the strings of length n which contain n−2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order.
Recall that the string s of length n is lexicographically less than string t of length n , if there exists such i ( 1≤i≤n ), that si<ti , and for any j ( 1≤j<i ) sj=tj . The lexicographic comparison of strings is implemented by the operator < in modern programming languages.
For example, if n=5 the strings are (the order does matter):
- aaabb
- aabab
- aabba
- abaab
- ababa
- abbaa
- baaab
- baaba
- babaa
- bbaaa
It is easy to show that such a list of strings will contain exactly 2n⋅(n−1) strings.
You are given n ( n>2 ) and k ( 1≤k≤2n⋅(n−1) ). Print the k -th string from the list.
输入格式
The input contains one or more test cases.
The first line contains one integer t ( 1≤t≤104 ) — the number of test cases in the test. Then t test cases follow.
Each test case is written on the the separate line containing two integers n and k ( 3≤n≤105,1≤k≤min(2⋅109,2n⋅(n−1)) .
The sum of values n over all test cases in the test doesn't exceed 105 .
输出格式
For each test case print the k -th string from the list of all described above strings of length n . Strings in the list are sorted lexicographically (alphabetically).
输入输出样例
输入#1
7 5 1 5 2 5 8 5 10 3 1 3 2 20 100
输出#1
aaabb aabab baaba bbaaa abb bab aaaaabaaaaabaaaaaaaa