No.8014 An Educational Problem on Polynomial Hashing
タグ : / 解いたユーザー数 14
作問者 :
anta
Problem Statement
The polynomial hash (also known as the rolling hash or the Karp-Rabin fingerprint) takes integers $P, B$ as parameters and is defined for a string $S$ as \[ h_{P,B}(S) = (\sum_{i=1}^{|S|} B^{|S|-i} {\rm ord}(S_i)) \bmod P \] Here, $|S|$ denotes the length of $S$. ${\rm ord}(c)$ denotes the ASCII code of the character $c$ ('a'–'z' are 97–122). $x \bmod P$ denotes the remainder when $x$ is divided by $P$.
You are given $P$, $B$. Find one pair of strings $S, T$ that satisfies all of the following conditions:
- $S \neq T$
- $|S| = |T|$
- $1 \le |S|, |T| \le 10^5$
- $S, T$ each consist only of lowercase English letters ('a'–'z').
- $h_{P,B}(S) = h_{P,B}(T)$
Input
$P$ $B$
The first and second lines give the integers $P$ and $B$, the parameters of the polynomial hash function.
Note that there is only one test case, and its content is guaranteed to be as follows.
1000000000000000003 123456789987654321
Output
$S$ $T$
Output $S, T$ satisfying the conditions of the problem statement on two lines.
Sample
Sample 1
Input
1009 123
Output
bab wbe
We have $h_{P,B}(S) = h_{P,B}(T) = 342$.
Sample 2
Input
1000000007 123456789
Output
hkmpqvm axlszsi
We have $h_{P,B}(S) = h_{P,B}(T) = 409775251$.
Hint
The values of $P,B$ in the test case have no particular deep meaning.
Even for $0 \le B < P \le 10^{18}$, it is not guaranteed that the intended solution always outputs a correct answer within the time limit for arbitrary input.
However, it does generate the answer for the test case within the time limit, rather than simply embedding it.
Therefore, please solve this problem by a method other than embedding the answer.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。