Rohan and Company
Practice
0 (0 votes)
Medium
Problem
59% Success 86 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Recently a company came into existence and had a impressive growth over past 2 years. The assets of the company is given by the P-value. The value is calculated by GCD of all contributions presented in the form of an array.

Let us call the prefix of size K of array A as another array which contains only first K elements of array A. You are given contributions in form of array A. Founder of company wanted to know the minimum size of prefix that could be removed such that P-value remaining array is maximised.

Also Q queries are given and in each query a range is given by L and R and we have to find the maximum GCD that can be obtained by removing a prefix K of any size in the given range.

INPUT:
First line contains an integer N denoting the size of array A.
Next line contains N space separated integers denoting the array A.
Next line contains an integer Q.
Then follow Q lines each represented using two integers L and R.

OUTPUT:
Firstly, print a single integer, the size of the prefix that should be removed so that the P−Value of the remaining array is maximised.
If there are several possible answers, print the length of minimum size prefix.
After it Q lines follow each representing the answer related to each query.

CONSTRAINTS:
2 ≤ N ≤ \(10^{5}\)
1 ≤ A[i] ≤ \(10^{6}\)
1 ≤ Q ≤ \(10^{5}\)
1 ≤ L ≤ R ≤ N

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
MediumNumber TheoryGreatest common divisorAlgorithmsMathematicsOpenApproved
Points:30
4 votes
Tags:
MathematicsMediumGreatest common divisorGreatest common divisor
Points:30
1 votes
Tags:
GCDNumber TheoryC++Math