#5. INFINITY
INFINITY
Problem Statement
Given a string , define an operation that appends a right rotation of string to the end of itself.
Right rotation means that the last character of becomes the first character of the new string, while the remaining characters retain their original order.
Starting from the initial string , by repeatedly applying the operation, an infinite-length string is generated. Each operation doubles the length of the string.
Given the initial string and an index , find the character at the position in the infinitely generated string. The index is 1-based.
Input
The input consists of a single line containing a string , followed by an integer , separated by a space. The string contains up to 30 uppercase letters, and .
Output
Output the character at the position in the infinite string.
Example
Input
NUAA 10
Output
N
Explanation
Note that can be very large, beyond the range of standard 32-bit integers, so you may need to use a 64-bit integer type (such as "long long" in C/C++).
In this example, the initial string "NUAA" expands infinitely as follows:
NUAA -> NUAAANUA -> NUAAANUAANUAAANU -> ..
The character at index is "N".
相关
在下列比赛中: