Find an integer that is common in the maximum number of given arithmetic progressions | Python implementation of the approach ; Function to return element common in maximum number of APs ; Initialize the count variable ; Increment count for every element of an AP ; Find the index with maximum count ; Return the maximum common element ; Driver code
MAXN = 1000000 NEW_LINE def maxCommonElement ( A , D , N ) : NEW_LINE INDENT cnt = [ 0 ] * MAXN NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( A [ i ] , MAXN , D [ i ] ) : NEW_LINE INDENT cnt [ j ] += 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE com = 0 NEW_LINE for i in range ( MAXN ) : NEW_LINE INDENT if cnt [ i ] > ans : NEW_LINE INDENT ans = cnt [ i ] NEW_LINE com = i NEW_LINE DEDENT DEDENT return com NEW_LINE DEDENT A = [ 13 , 1 , 2 , 5 ] NEW_LINE D = [ 5 , 10 , 1 , 12 ] NEW_LINE N = len ( A ) NEW_LINE print ( maxCommonElement ( A , D , N ) ) NEW_LINE