Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Congress and BJP , two political rivals, are facing a mathematical challenge related to their electoral numbers. They define a GCD sequence as follows: given
Congress and BJP two political rivals, are facing a mathematical challenge
related to their electoral numbers. They define a GCD sequence as follows: given an
array A of n positive integers, they calculate the GCD of each neighboring pair of
numbers to create a new array B
The GCD sequence B is defined as follows: Bi GCDAi Ai
for all i n
Congress and BJP are intrigued by the idea of transforming an array A by removing
exactly one number so that the resulting GCD sequence B is nondecreasing. They are
wondering if this is possible for various arrays they encounter.
Can you help them determine whether removing exactly one number from array A is
possible so that the resulting GCD sequence B is nondecreasing?
The required time complexity is less than On
and mention your proposed solution
time complexity in the code.
Here are the details:
Input format:
The first line contains a single integer n the number of elements in the array A
The second line contains n spaceseparated integers Ai the electoral numbers of
array A
Output format:
Output YES if it's possible to remove exactly one number from the array A so that the
resulting GCDsequence B is nondecreasing. Otherwise, output NO
Constraints:
n
Ai
Example :
Output: YES
Example :
Output: YES
Example :
Output: NO
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started