#P1773. 符文之语
符文之语
Description
When Little FF arrived, the temple was already in ruins. But at the center stood a stone pedestal that was bright and spotless. Little FF approached and found a string of digits on the pedestal, with a line of ancient runic words carved above it. Being fluent in ancient runes, Little FF easily understood the text, which roughly says:
Given the string of digits on the pedestal, you may insert multiplication signs at suitable positions (suppose you insert of them; you may also insert none, i.e., split into parts). Let the product of these parts (if , the product is just the value of the original string) modulo be (that is, ).
Find the minimum possible and, among all ways achieving it, the smallest ; and find the maximum possible and, among all ways achieving it, the smallest (it is possible that the minimum and maximum are the same).
Little FF also knows that if he finds the correct answer, he can proceed to the lower level of the temple. But this problem seems hard, so he turns to you for help, and promises an eighty–twenty split of the treasure afterwards (you get twenty).
Input Format
The first line contains the string of digits, which does not contain the digit .
The second line contains .
Output Format
Output four numbers: the minimum value of and, in that case, the smallest ; then the maximum value of and, in that case, the smallest . Separate adjacent numbers with a single space.
4421
22
0 1 21 0
Hint
Let be the length of the string.
- For of the testdata: .
- For of the testdata: , .
NOI Guide 2010 Senior (02).
Translated by ChatGPT 5
京公网安备 11011102002149号