XOR Hashing
InterviewTime limit1sMemory limit1024 MB
Each hash value 0 to 2^N-1 is equally likely for a random point, and the task asks for the chance that M random picks contain two with the same value, modulo 10^9+7.
- Level
Medium4 of 10
- Topics
- Probability, Math, Combinatorics
- Solved
- No attempts yet
Problem
Every point on a plane whose and coordinates are integers with is assigned the value , the XOR of its two coordinates. Mapping data to other data this way is called hashing, and the mapped value is called the hash value.
A point with an assigned value is chosen times. Each choice is made with equal probability, and the same point may be chosen more than once. Find the probability that two of the chosen points have the same hash value.
Input
The first line contains integers and separated by a space.
Output
Let the probability that two chosen points share a hash value be , where and are coprime non-negative integers and . Print . is the modular multiplicative inverse of .
You can prove that the probability is always a rational number.