Greatest Common Divisor
Time limit1sMemory limit1024 MB
Given an array of n numbers and a window length k, find the largest GCD of any contiguous subarray of length k.
- Level
Medium6 of 10
- Topics
- Sliding window, Number theory, Queue
- Solved
- No attempts yet
Problem
The greatest common divisor of a nonempty set of natural numbers is the largest natural number that divides every number in .
You are given an array of natural numbers and an integer . Choose a contiguous subarray of length so that its greatest common divisor is as large as possible, and output that value.
Input
The first line contains two integers and (, ).
The second line contains natural numbers ().
Output
Print one natural number: the maximum possible greatest common divisor of a subarray of length .