AmazonOA #54
Find Hash (Distinct Hash Values)
Estimated EasyJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
For each position you may freely choose a non-negative secretKey, giving hash[i]=secretKey[i] mod param[i]. Find the maximum number of distinct values in the hash array.
Input
The first line contains n (1..200000), and the second line contains n param values (1..10⁹).
Output
Output a single integer answer.
Example 1
Input:
3
1 2 4
Output:
3
Example 2
Input:
2
1 1
Output:
1
Example 3
Input:
1
3
Output:
1
Example notes
Example 1: remainders 0, 1, 2 can be chosen, 3 in total. Example 2: modulo 1 can only give 0, so there is 1 value. Example 3: there is only one position, so at most 1 value.
Editorial
Loading solution…