human
Program to find last two digits of 2 ^ n | Iterative Function to calculate ( x ^ y ) % p in O ( log y ).
x = x % p 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 >> 1 y = y / 2.
function to calculate number of digits in x.
function to print last 2 digits of 2 ^ n.
Generating 10 ^ 2.
Calling modular exponentiation.
Printing leftmost zeros . Since ( 2 ^ n ) % 2 can have digits less then 2. In that case we need to print zeros.
If temp is not zero then print temp If temp is zero then already printed.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to program to find last two digits of 2 ^ n and the other steps required.
 def power ( x , y , p ) :
	while ( y > 0 ) :
		if ( y & 1 ) :
			res = ( res * x ) % p
		x = ( x * x ) % p
	return res
def numberOfDigits ( x ) :
	i = 0
	while ( x ) :
		x //= 10
		i += 1
	return i
def LastTwoDigit ( n ) :
	print ( " Last ▁ " + str ( 2 ) + " ▁ digits ▁ of ▁ " + str ( 2 ) , end = " " )
	print ( " ^ " + str ( n ) + " ▁ = ▁ " , end = " " )
	temp = 1
	for i in range ( 1 , 3 ) :
		temp *= 10
	temp = power ( 2 , n , temp )
	for i in range ( 2 - numberOfDigits ( temp ) ) :
		print ( 0 , end = " " )
	if temp :
		print ( temp )
if __name__ == " _ _ main _ _ " :
	n = 72
	LastTwoDigit ( n )