human
Find First element in AP which is multiple of given prime | Iterative Function to calculate ( x ^ y ) % p in O ( log y ).
Initialize result.
Update x if it is more than or equal to p.
If y is odd , multiply x with result.
y must be even now y = y / 2.
function to find nearest element in common.
base conditions.
Driver Code.
module both A and D.
function call"
How can the above be solved in Python?

Write me a code to find First element in AP which is multiple of given prime and the other steps required?
assistant
#Here is code to find First element in AP which is multiple of given prime and the other steps required.
 def power ( x , y , p ) :
	res = 1
	x = x % p
	while y > 0 :
		if y & 1 :
			res = ( res * x ) % p
		y = y >> 1
		x = ( x * x ) % p
	return res
def NearestElement ( A , D , P ) :
	if A == 0 :
		return 0
	elif D == 0 :
		return - 1
	else :
		X = power ( D , P - 2 , P )
		return ( X * ( P - A ) ) % P
if __name__ == " _ _ main _ _ " :
	A , D , P = 4 , 9 , 11
	A %= P
	D %= P
	print ( NearestElement ( A , D , P ) )