Given two numbers A and B, find K^{th} digit from right of A^{B}.
 
Example 1:
Input:
A = 3
B = 3
K = 1
Output:
7
Explanation:
3^{3 }= 27 and 1st
digit from right is 
7
Example 2:
Input:
A = 5
B = 2
K = 2
Output:
2
Explanation:
5^{2 }= 25 and second
digit from right is
2.
Your Task:
You don't need to read input or print anything. Your task is to complete the function kthDigit() which takes integers A, B, K as input parameters and returns K^{th }Digit of A^{B} from right side.
 
Expected Time Complexity: O(log A^{B})
Expected Space Complexity: O(1)
 
Constraints:
1 <= A,B <= 15
1 <=K<= digits in A^{B}

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(log A^{B})
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:
    def kthDigit(self, A, B, K):
        # code here

Solutions:
class Solution:

	def kthDigit(self, A, B, K):
		val = A ** B
		val = str(val)[::-1]
		return val[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		power = A ** B
		return str(power)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		a = A ** B
		return int(str(a)[-K])


class Solution:

	def kthDigit(self, A, B, K):
		d = pow(A, B)
		d = str(d)[::-1]
		return d[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		sum = A ** B
		j = len(str(sum))
		return int(str(sum)[j - K])


class Solution:

	def kthDigit(self, A, B, K):
		pow = str(A ** B)
		return pow[-K]


class Solution:

	def kthDigit(self, A, B, K):
		n = pow(A, B)
		while K > 1:
			n = n // 10
			K = K - 1
		return n % 10


class Solution:

	def kthDigit(self, A, B, K):
		C = A ** B
		return str(C)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		num = str(A ** B)
		return num[-K]


class Solution:

	def kthDigit(self, A, B, k):
		p = pow(A, B)
		for i in range(k):
			ans = p % 10
			p = int(p / 10)
		return ans


class Solution:

	def kthDigit(self, A, B, K):
		res = A ** B
		a = []
		s = str(res)
		for i in s:
			a.append(i)
		a.reverse()
		res = int(a[K - 1])
		return res


class Solution:

	def kthDigit(self, A, B, K):
		n = pow(A, B)
		s = str(n)
		s = s[::-1]
		return s[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		num = A ** B
		for i in range(K):
			r = num % 10
			num = num // 10
		return r


class Solution:

	def kthDigit(self, A, B, K):
		try:
			x = str(int(pow(A, B)))[-K]
		except:
			x = 0
		return x


class Solution:

	def kthDigit(self, A, B, K):
		res = int(A) ** int(B)
		temp = 0
		while K > 0:
			temp = res % 10
			res //= 10
			K -= 1
		return temp


class Solution:

	def kthDigit(self, A, B, K):
		res = int(A) ** int(B)
		return str(res)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		di = A ** B
		return str(di)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		p = pow(A, B)
		c = str(p)
		return c[-K]


class Solution:

	def kthDigit(self, A, B, K):
		ans = A ** B
		if len(str(ans)) >= K:
			return str(ans)[-K]
		return -1


class Solution:

	def kthDigit(self, A, B, K):
		n = A ** B
		x = str(n)
		l = []
		for i in x:
			l.append(i)
		return int(l[-K])


class Solution:

	def kthDigit(self, A, B, K):
		m = str(int(A ** B))
		return m[-K]


class Solution:

	def kthDigit(self, A, B, K):
		l = A ** B
		t = str(l)
		return t[-K]


class Solution:

	def kthDigit(self, A, B, K):
		c = pow(A, B)
		b = str(c)
		n = len(b)
		return b[n - K]


class Solution:

	def kthDigit(self, A, B, K):
		x = A ** B
		i = 0
		while i < K:
			m = 0
			m = x % 10
			x = x // 10
			i = i + 1
		return m


class Solution:

	def kthDigit(self, A, B, K):
		temp = A ** B
		return str(temp)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		r = str(A ** B)
		return r[len(r) - K]


class Solution:

	def kthDigit(self, A, B, K):
		n = A ** B
		s = str(n)
		d = s[-K]
		d = int(d)
		return d


import math

class Solution:

	def kthDigit(self, A, B, K):
		c = 0
		p = math.pow(A, B)
		while p > 0 and c < K:
			r = int(p % 10)
			c = c + 1
			if c == K:
				return r
			p = p // 10


class Solution:

	def kthDigit(self, A, B, K):
		M = A ** B
		Z = int(M / 10 ** (K - 1))
		Z1 = Z % 10
		return Z1


import math

class Solution:

	def kthDigit(self, A, B, K):
		res = pow(A, B)
		c = 0
		while res > 0:
			c = c + 1
			r = res % 10
			if c == K:
				return r
			res = res // 10
		return


class Solution:

	def kthDigit(self, A, B, K):
		x = A ** B
		if K == 1:
			return x % 10
		else:
			for i in range(K - 1):
				x = x // 10
			return x % 10


class Solution:

	def kthDigit(self, A, B, K):
		p = A ** B
		return str(p)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		p = A
		for i in range(B - 1):
			p = p * A
		x = pow(10, K - 1)
		p = p / x
		return int(p % 10)


class Solution:

	def kthDigit(self, A, B, K):
		result = str(A ** B)
		kth_digit = result[-K]
		return kth_digit


class Solution:

	def kthDigit(self, A, B, K):
		p = A ** B
		l = []
		while p > 0:
			l.append(p % 10)
			p = p // 10
		return l[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		power = A ** B
		power_str = str(power)
		len_power_str = len(power_str)
		index = len_power_str - K
		d_f_r = power_str[index]
		return d_f_r


class Solution:

	def kthDigit(self, A, B, K):
		power = A ** B
		len_str = str(power)
		l = len(len_str)
		index = l - K
		d_f_r = len_str[index]
		return d_f_r


class Solution:

	def kthDigit(self, A, B, k):
		A = A ** B
		A = str(A)
		return A[-k]


class Solution:

	def kthDigit(self, A, B, K):
		n = int(str(pow(A, B))[-K])
		return n


class Solution:

	def kthDigit(self, A, B, K):
		res = pow(A, B)
		s = str(res)
		s = s[::-1]
		return int(s[K - 1])


class Solution:

	def kthDigit(self, A, B, K):
		num = A ** B
		num1 = num
		l = []
		while num1:
			rem = num1 % 10
			l.append(rem)
			num1 = num1 // 10
		l = l[::-1]
		return l[-K]


from math import pow

class Solution:

	def kthDigit(self, A, B, K):
		a = round(pow(int(A), int(B)))
		b = str(a)
		b = b[::-1]
		return b[K - 1]


import math

class Solution:

	def kthDigit(self, A, B, K):
		numb = A ** B
		b = ''
		for i in str(numb)[::-1]:
			b = b + i
		for j in b:
			kth = int(b[K - 1])
		return kth


class Solution:

	def kthDigit(self, A, B, K):
		c = str(int(A) ** int(B))
		if len(c) == 1 and K == 1:
			return c
		if K < len(c):
			return c[-K]
		return c[0]


class Solution:

	def kthDigit(self, A, B, K):
		l = A ** B
		s = str(l)
		s = s[::-1]
		return s[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		p = str(A ** B)
		q = p[::-1]
		return q[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		return A ** B % 10 ** K // 10 ** (K - 1)


class Solution:

	def kthDigit(self, A, B, K):
		c = A ** B
		c = list(str(c))
		d = c[::-1]
		for i in range(0, len(d)):
			if K == i + 1:
				return d[i]


class Solution:

	def kthDigit(self, A, B, K):
		var = A ** B
		for i in range(K):
			if i == K - 1:
				return var % 10
			var = var // 10


class Solution:

	def kthDigit(self, A, B, K):
		temp = A ** B
		temp1 = -1
		return str(temp)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		n = A ** B
		return str(n)[-K]


class Solution:

	def kthDigit(self, A, B, K):
		c = A ** B
		t = []
		for i in str(c):
			t.append(i)
		return t[-K]


class Solution:

	def kthDigit(self, A, B, K):
		y = str(A ** B)
		l = [int(i) for i in y]
		return l[-K]


class Solution:

	def kthDigit(self, A, B, K):
		res = A ** B
		rs = str(res)
		return rs[-K]


class Solution:

	def kthDigit(self, A, B, K):
		p = A ** B
		p = str(p)
		l = len(p)
		if K > l:
			return 0
		l = l - K
		return p[l]


class Solution:

	def kthDigit(self, A, B, K):
		temp = A ** B
		t = 1
		while temp > 0:
			if t == K:
				return temp % 10
			temp = temp // 10
			t += 1


class Solution:

	def kthDigit(self, A, B, k):
		res = pow(A, B)
		while k > 0:
			digit = res % 10
			k -= 1
			res //= 10
		return digit


import math

class Solution:

	def kthDigit(self, A, B, K):
		x = int(pow(A, B))
		y = str(x)
		return y[-K]


class Solution:

	def kthDigit(self, a, b, k):
		c = str(a ** b)
		return c[-k]


class Solution:

	def kthDigit(self, A, B, K):
		s = A ** B
		s1 = str(s)
		t = len(s1) - K
		return int(s1[t])


class Solution:

	def kthDigit(self, A, B, K):
		ans = str(A ** B)
		return ans[-K]


class Solution:

	def kthDigit(self, A, B, K):
		power = str(A ** B)
		res = ''
		for i in power:
			res = i + res
		m = K - 1
		return res[m]


class Solution:

	def kthDigit(self, a, b, k):
		x = a ** b
		x = str(x)
		return x[-k]


class Solution:

	def kthDigit(self, A, B, K):
		mul = 1
		for i in range(B):
			mul = mul * A
		a = str(mul)
		l = K * -1
		return a[l]


class Solution:

	def kthDigit(self, A, B, K):
		number = pow(A, B)
		num = number
		count = 0
		while num != 0:
			temp = num % 10
			num //= 10
			count += 1
			if count == K:
				return temp


class Solution:

	def kthDigit(self, A, B, K):
		ans = str(pow(A, B, 10 ** K))
		ans = (K - len(ans)) * '0' + ans
		return ans[0]


class Solution:

	def kthDigit(self, A, B, K):
		c = pow(A, B)
		d = str(c)
		d = list(d)
		return d[-K]


class Solution:

	def kthDigit(self, A, B, K):
		new = []
		num = pow(A, B)
		while num != 0:
			d = num % 10
			new.append(d)
			num = num // 10
		return new[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		x = A ** B
		c = 0
		while x:
			r = x % 10
			c += 1
			if c == K:
				return r
			x = x // 10
		return 0


class Solution:

	def kthDigit(self, A, B, K):
		ans = A ** B
		l = []
		ans = str(ans)
		for i in ans:
			l.append(i)
		l.reverse()
		return l[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		c = A ** B
		s = 0
		while c > 0 and s < K:
			r = c % 10
			s = s + 1
			if s == K:
				return r
			c = c // 10


class Solution:

	def kthDigit(self, A, B, K):
		string = str(A ** B)
		res = ''
		for i in range(len(string) - 1, -1, -1):
			res = res + string[i]
		return res[K - 1]


class Solution:

	def kthDigit(self, A, B, K):
		c = str(A ** B)
		return int(c[-K])