Maximum GCD of all subarrays of length at least 2 | Function to find GCD ; To store the maximum GCD ; Traverse the array ; Find GCD of the consecutive element ; If calculated GCD > maxGCD then update it ; Print the maximum GCD ; Driver Code ; Function call
def gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a ; NEW_LINE DEDENT return gcd ( b , a % b ) ; NEW_LINE DEDENT def findMaxGCD ( arr , n ) : NEW_LINE INDENT maxGCD = 0 ; NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT val = gcd ( arr [ i ] , arr [ i + 1 ] ) ; NEW_LINE if ( val > maxGCD ) : NEW_LINE INDENT maxGCD = val ; NEW_LINE DEDENT DEDENT print ( maxGCD ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 18 , 9 , 9 , 5 , 15 , 8 , 7 , 6 , 9 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE findMaxGCD ( arr , n ) ; NEW_LINE DEDENT