Count Non | Python3 program of the above approach ; Function to find the gcd of the two numbers ; Function to find distinct elements in the array by repeatidely inserting the absolute difference of all possible pairs ; Stores largest element of the array ; Traverse the array , arr [ ] ; Update max_value ; Stores GCD of array ; Update GCDArr ; Stores distinct elements in the array by repeatedely inserting absolute difference of all possible pairs ; Given array arr [ ]
import sys NEW_LINE def gcd ( a , b ) : NEW_LINE INDENT if a == 0 : NEW_LINE INDENT return b NEW_LINE DEDENT return gcd ( b % a , a ) NEW_LINE DEDENT def DistinctValues ( arr , N ) : NEW_LINE INDENT max_value = - sys . maxsize - 1 NEW_LINE for i in range ( 1 , N ) : NEW_LINE max_value = max ( arr ) NEW_LINE GCDArr = arr [ 0 ] NEW_LINE INDENT GCDArr = gcd ( GCDArr , arr [ i ] ) NEW_LINE DEDENT answer = max_value // GCDArr NEW_LINE return answer + 1 NEW_LINE DEDENT arr = [ 4 , 12 , 16 , 24 ] NEW_LINE N = len ( arr ) NEW_LINE print ( DistinctValues ( arr , N ) ) NEW_LINE