Answer the question
In order to leave comments, you need to log in
How to make polynomial hashing more stable?
Solutions with polynomial hashes are hacked
on codeforces .
And how to write, so as not to be hacked?
Answer the question
In order to leave comments, you need to log in
As they
write here
Hashes must be with a randomized multiplier/modulus, and the modulus must be simple, otherwise you will get caught sooner or later!
First, the module P must be simple.
Explanation: H mod P = a, if P is prime, then we get the total number of residues - the number of different values of A will be equal to P (0...P-1). If P is composite, then there will be collisions. This follows from Euler's theorem.
The article says how hashes with P = 2^64 are cracked, which is obviously not prime :)
Secondly, the more P, the better, because. more hash values. Usually they take (10^9)+7
In programming Olympiads, this is enough.
Thirdly (not for Olympiads), it is possible to duplicate hash calculations for several modules P1, P2, P3.
The probability that all three hashes will give a collision is almost unbelievable, but possible.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question