#C14132. Longest Contiguous Divisible Subarray

    ID: 43748 Type: Default 1000ms 256MiB

Longest Contiguous Divisible Subarray

Longest Contiguous Divisible Subarray

You are given an array of integers and an integer divisor k. Your task is to find the longest contiguous subarray in which every element is divisible by k, i.e., for every element a in the subarray, it must hold that \(a \mod k = 0\).

If multiple subarrays have the maximum length, output the one that appears first. If no element in the array is divisible by k, output None for the subarray and indices -1 -1.

inputFormat

The input is taken from standard input (stdin) with the following format:

  1. The first line contains an integer n representing the number of elements in the array.
  2. The second line contains n space‐separated integers which make up the array.
  3. The third line contains the integer k, which is the divisor.

outputFormat

Print the result to standard output (stdout) in two lines:

  1. The first line should contain the longest contiguous subarray’s elements separated by a space. If no such subarray exists, output None.
  2. The second line should contain two space‐separated integers representing the starting and ending indices (0-indexed) of the subarray. If no valid subarray exists, print -1 -1.
## sample
7
5 10 15 20 25 30 35
5
5 10 15 20 25 30 35

0 6

</p>