An apprentice alchemist owns a warding scroll that begins as a single inked rune: the letter a. Each night the alchemist performs the same ritual: the entire current scroll is copied, and the copy is appended to the end of the original scroll — but every rune on the freshly appended copy is advanced one letter forward in the alphabet (a becomes b, b becomes c, ..., and z wraps back around to a). The scroll therefore doubles in length every night. The ritual repeats, night after night, until the scroll holds at least k runes; the alchemist then stops and reads off the rune sitting in the k-th position, counting the very first rune as position 1.
Given k, determine which rune occupies position k once the ritual stops.
A single line containing one integer, k.
A single line containing one lowercase letter: the rune at position k.
1 <= k <= 100000Example 1
Input
5
Expected
b
Explanation
Night 0 the scroll is "a". Night 1: "a"+"b"="ab". Night 2: "ab"+"bc"="abbc". Night 3: "abbc"+"bccd"="abbcbccd", which has length 8 >= 5, so the ritual stops. Counting from position 1, the 5th rune of "abbcbccd" is 'b'.
Example 2
Input
8
Expected
d
Explanation
Using the same finished scroll "abbcbccd" (length 8, reached after night 3) from Example 1, the 8th rune — the last one — is 'd'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →