GCD
Time limit4sMemory limit512 MB
Given an array of up to 1e5 integers up to 1e18, erase at most k elements to maximize the GCD of the remaining elements.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Probability
- Solved
- No attempts yet
Problem
You are given an array of integers . Find the maximum possible greatest common divisor of all numbers in the array if you can erase no more than elements () from it.
Input
The first line contains two integers , the number of elements in the array, and , the maximum number of elements you can erase (, ). The second line contains integers , the array ().
Output
Print the maximum possible greatest common divisor of all elements left in the array after erasing no more than elements.