問題一覧 > 教育的問題

No.8014 An Educational Problem on Polynomial Hashing

レベル : / AI推定難易度 : 2500 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 256 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 14
作問者 : anta
お気に入りにしたユーザー ProblemId : 804 / 自分の提出
問題文最終更新日: 2026-06-25 01:57:33
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original

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)$
If there are multiple answers, you may output any of them.

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もしくは右上の雲マークをクリックしてアカウントを作成してください。