Answer to Question #296877 in Python for Ram

Question #296877

New Dictionary


Peter is making a new dictionary.He wants to arrange the words in the ascending order of their length and later arrange the ones with the same length in lexicographic order.Each word is given a serial number according to its position.Find the word according to the serial number.


Input

The first line of input is a positive integer which is the serial number.


Output

The output should be a single line containing the word that represents the serial number.


Explanation

Given serial number is 42.

As the serial number is between 26 and 52, the first character of the word is A.The remaining counter of the serial number is 16 (42-26).

The second character of the word is the 16th alphabet, which is P.

So, the output should be AP.


Sample Input1

42

Sample Output1

AP


Sample input2

751

Sample output2

ABW


1
Expert's answer
2022-02-12T04:42:21-0500
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
length = 1
while (n - 1) // 26 ** length:
    n -= 26 ** length
    length += 1
rez = ''
for i in range(length):
    ind = (n - 1) // 26 ** (length - i - 1)
    rez += letters[ind]
    n -= 26 ** (length - i - 1) * ind

print(rez)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS