#Lutece1314. Hash Perfectly
Hash Perfectly
Migrated from Lutece 1314 Hash Perfectly
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
In computing, a hash table is a data structure used to implement an associative array, a structure that can map keys to values.
A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found. A common hash function is ( is modulo operator), but it may cause some collisions.
For example, if keys are , and we choose , the indexes will be , where some collisions happen.
To solve the collision, we can use the method known as separate chaining with linked lists.
Seeing the example again, when we try to insert , because its index is used, we build a linked list in index , and there would be in index . Insert next, there would be a linked list in index 2.
To calculate the efficiency of the hash function, we define a value called (Average search length):
is the number of times to compare when we search the key.
Using the example above again, , so .
It's obvious that can minimize when we choose a sufficiently large , but in fact due to the limitation of memory, must be no more than , i.e., .
Now you are given n keys, try to choose a proper to minimize . If there are multiple answers, choose the smallest one.
Input
The first line contains two integers and .
The second line contains integers, where integer indicates the key.
Output
Print the smallest which can minimize .
Samples
4 4
1 2 6 10
3
Note
In sample,
if , the indexes will be , so ;
if , the indexes will be , so ;
if , the indexes will be , so ;
if , the indexes will be , so ;
So the answer is .
Resources
The 14th UESTC Programming Contest Final