human
What is a code to sum of Digits in a ^ n till a single digit and the other steps required given the following:
Sum of Digits in a ^ n till a single digit | This function finds single digit sum of n ..
Returns single digit sum of a ^ n . We use modular exponentiation technique ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to sum of Digits in a ^ n till a single digit and the other steps required.
 def digSum ( n ) :
	if n == 0 :
		return 0
	elif n % 9 == 0 :
		return 9
	else :
		return n % 9
def powerDigitSum ( a , n ) :
	res = 1
	while ( n ) :
		if n % 2 == 1 :
			res = res * digSum ( a )
			res = digSum ( res )
		a = digSum ( digSum ( a ) * digSum ( a ) )
		n //= 2
	return res
if __name__ == " _ _ main _ _ " :
	a , n = 9 , 4
	print ( powerDigitSum ( a , n ) )