#P7350. 「MCOI-04」Dream and Strings
「MCOI-04」Dream and Strings
Description
Tommy’s encryption system uses the following string hash algorithm:
int Hash(std::string s, int base, int mod) {
int result = 0;
for(int i=0; i<s.length(); i++)
result = (1ll * result * base + s[i]) % mod;
return result;
}
Here, and are given parameters, satisfying , and is a prime number.
Now Dream wants to crack Tommy’s ciphertext. First, Dream needs to find a suitable hash collision. Given , , and a string , find a string of the same length such that , , but and differ at least at one position.
If there are multiple valid , output any one of them.
Input Format
The first line contains two positive integers and .
The second line contains a string consisting of lowercase letters.
Output Format
Output one line containing a string consisting of lowercase letters, representing the answer.
257 997
aabdccbabdcdcadbcabcabaabdbbddbaabcadabcbcdacbbaac
lmzaeccihyailccmzzaxshssgbvjvhthllyofzudraatifnzxy
Hint
Constraints
If is a string, is its length.
For the first of the testdata, .
For the first of the testdata, and is random.
For of the testdata, , , and is a prime number.
Notes
Minecraft OI Round 4 D
idea & solution: w33z8kqrqk8zzzx33 check: MatKave
Translated by ChatGPT 5
京公网安备 11011102002149号