Maximise GCD

3.2

12 votes
Mathematics, Easy, Number Theory
Problem

Let us denote by GValue the GCD of all elements of an array. Let us call the prefix of size P (P1) of an array A as another array which contains only the first P elements of the array A.

You are given an array A of N integers. You need to remove some prefix of the array so that the GValue of the remaining array (after removing the prefix) is maximised. You need to print the size of the prefix that should be removed. If there are several possible answers, print the length of minimum size prefix.

Input:

First line contains an integer N, denoting the size of array A. Next line contains N space separated integers denoting the array A.

Output:

Print a single integer, the size of the prefix that should be removed so that the GValue of the remaining array is maximised. If there are several possible answers, print the length of minimum size prefix.

Constraints:

2N103

1Ai106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

If we remove size 2 prefix, the GValue of remaining array [6, 9, 3] becomes 3.

Editor Image

?