[Solution] Alternating Strings CodeChef Solution | CodeChef Problem Solution 2022
Chef likes to spend his summer vacation playing with strings. Chef likes alternating patterns, but he only likes the characters and , so he does the following:
Chef starts with an empty string . Then,
- First, he appends once to
- Next, he appends twice to
- Next, he appends thrice to
- Next, he appends four times to
and so on. For example, the first characters of are .
Now, Chef takes the string formed by the first characters of , and wants to calculate its beauty. The beauty of a string is calculated as follows:
Solution Click Below:- CLICK HERE
- First, we define the value of a string to be the number of positions such that . For example, the value of is and the value of is .
- Then, the beauty of a string is defined to be the sum of values of all its substrings. Two substrings are considered distinct if they occur at different positions, so every string of length has exactly substrings.
You are given . Help Chef by calculating the beauty of the string formed by the first characters of . The answer may be large, so report it modulo .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains a single integer .
Output Format
For each test case, output in a single line the beauty of the string modulo .
No comments:
Post a Comment