arr [ i ] can be derived from D only if | arr [ i ] - D | is divisible by gcd of A and B
if ( ( abs ( arr [ i ] - D ) % gcdAB ) == 0 ) : NEW_LINE INDENT counter += 1 NEW_LINE DEDENT return counter NEW_LINE