SETI
Time limit1sMemory limit128 MB
Recover the coefficients a_0..a_{n-1} of a polynomial over a prime field from its values at k = 1..n.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
For years, scientists have listened to radio signals from space, hoping to understand what distant civilizations might be trying to say. One especially interesting source is a faraway nebula.
Researchers found that if each message is transmitted as a sequence of integers , then, when the correct value of is used, the function
always evaluates to a value in the range . Here is the length of the message, and each coefficient satisfies . The number is a prime that is guaranteed to be larger than both and , and never exceeds .
Linguists transcribe each message into a string over the English alphabet. The rule maps the values that may take to the letters a..z (that is, , , , ); the value is written as an asterisk *. Looping from to , they append the character corresponding to to the string.
Your task is to perform the reverse transcription: given the string and the value of that was used, recover the corresponding integer sequence .
Input
The first line contains a single positive integer , the number of test cases that follow. Each case is a single line containing the value of used for the transcription, followed by the string to be transcribed, separated by one space. The only characters allowed in the string are the lowercase letters a..z and the asterisk *, and no string is longer than 70 characters.
Output
For each string, output one line with the recovered list of integers, separated by single spaces, given in ascending order of the index (from to ).