Hash Server
시간 제한2초메모리 제한2048 MB
알 수 없는 소수 매개변수 해시의 입출력 100쌍이 주어질 때 100개의 새 질의에 같은 해시 값을 계산해 답한다.
문제
This is an interactive, run-twice problem.
There is a hash server whose purpose is to hash strings of length . However, it has a problem: it is about to stop working, as it can only handle more strings. Your task is to write a program that can replicate the server's behavior.
A string is hashed as follows. Let be the -based alphabetic number of the -th letter. The hash is calculated using the following formula:
where the parameters , (), and () are distinct prime numbers from to , set on the hash server. These parameters are unknown constants.
To generate a response, the hash server converts the number into a string of length . It is written in the positional numeral system with base , but every digit is represented by a letter: represents digit , represents digit , etc. If the resulting number is too short, leading zeroes are added to make it exactly digits long.
Your program will run twice. During the first run, your program can make at most unique requests to the server. For every request, the hash server returns the hash of the given string.
During the second run, your program will receive a list of server responses from the first run in an arbitrary order. Your program must then process hash requests from the jury's program and produce the same responses as the original server.
힌트
The example of the second run contains only requests for brevity. In the testing system, the jury's program will make requests in the first test.
Here are the parameters that are used in the sample:
- .
- .
- .