#P12200. String Hash Collision
String Hash Collision
String Hash Collision
You are given two integers b and p. Your task is to find any two different strings s1 and s2 that satisfy the following conditions:
- Both strings consist only of lowercase letters (
a
toz
). - The two strings have the same length n where 1 \le n \le 104.
- s1 and s2 are not identical, but when hashed using the given hash function they produce the same hash value under the provided b and p.
The hash function is defined in C++ as follows:
[
\texttt{int strhash(const string &s, int b, int p) {
int val = 0;
for (int i = 0; i < s.length(); i++)
val = (1ll * val * b + s[i] - 'a' + 1) % p;
return val;
}}
]
It is guaranteed that the input parameters will allow a collision (i.e. two distinct strings with the same hash value) to exist.
inputFormat
The input consists of a single line with two integers b and p separated by spaces.
For example:
31 10
outputFormat
Output two lines. The first line should contain the first string, and the second line should contain the second string. These two strings must be different but have the same hash value computed by the given hash function.
sample
31 10
a
k
</p>