#P1773. 符文之语

    ID: 731 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp递推NOI 导刊枚举,暴力

符文之语

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 kk of them; you may also insert none, i.e., split into k+1k+1 parts). Let the product of these k+1k+1 parts (if k=0k=0, the product is just the value of the original string) modulo mm be xx (that is, mod m\bmod\ m).

Find the minimum possible xx and, among all ways achieving it, the smallest kk; and find the maximum possible xx and, among all ways achieving it, the smallest kk (it is possible that the minimum and maximum xx 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 00.

The second line contains mm.

Output Format

Output four numbers: the minimum value of xx and, in that case, the smallest kk; then the maximum value of xx and, in that case, the smallest kk. Separate adjacent numbers with a single space.

4421
22

0 1 21 0

Hint

Let LL be the length of the string.

  • For 30%30\% of the testdata: 2L502 \le L \le 50.
  • For 100%100\% of the testdata: 2L10002 \le L \le 1000, 2m502 \le m \le 50.

NOI Guide 2010 Senior (02).

Translated by ChatGPT 5