Given two integers X and N, you have to find an array such that it contains the frequency of index numbers occurring in (X^{1} X^{2} .... X^{N-1} X^{N}) . 
Example 1:
Input:
X = 15, N = 3
Output: 0 1 2 2 0 3 0 1 0 0
Explanation: 15^1, 15^2, 15^3 ==> 15, 225, 3375
An array which displays the frequency of 
its index numbers occuring in 15, 225 and 3375
Frequency of '0' = 0
Frequency of '1' = 1 (only once in 15)
Frequency of '2' = 2 (twice in 225)
Frequency of '3' = 2 (twice in 3375)
Frequency of '4' = 0
Frequency of '5' = 3 (thrice in '15', '225' and '3375')
Frequency of '6' = 0
Frequency of '7' = 1 (only once in '3375')
Frequency of '8' = 0
Frequency of '9' = 0
Resultant array:
0 1 2 2 0 3 0 1 0 0
Example 2:
Input:
X = 2, N = 4
Output: 0 1 1 0 1 0 1 0 1 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function getFreq() which takes the two integers x and n as parameters and returns an array of integers denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= X <= 15
1 <= N <= 15

Difficulty: EASY
Tags: Number theory

Data structures

Mathematics
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3





def getFreq(x, n):

    # code here

Solutions:
def getFreq(x, n):
	ans = []
	total_str = ''
	for i in range(1, n + 1):
		total_str += str(x ** i)
	for i in range(0, 10):
		ans.append(total_str.count(str(i)))
	return ans


def getFreq(x, n):
	ans = []
	for i in range(1, n + 1, 1):
		ans.append(x ** i)
	a = [0 for i in range(10)]
	for i in range(len(ans)):
		while ans[i]:
			a[ans[i] % 10] += 1
			ans[i] = ans[i] // 10
	return a


def getFreq(x, n):
	arr = [str(x ** i) for i in range(1, n + 1)]
	num = [int(val) for val in ''.join(arr)]
	res = []
	for i in range(10):
		res.append(num.count(i))
	return res


def getFreq(x, n):
	k = []
	s = ''
	for i in range(1, n + 1):
		s = s + str(x ** i)
	for i in range(10):
		i = str(i)
		fr = s.count(i)
		k.append(fr)
	return k


def getFreq(x, n):
	s = str(x)
	for i in range(2, n + 1):
		s += str(x ** i)
	digits = [0 for i in range(0, 10)]
	for i in range(0, len(s)):
		digits[int(s[i])] += 1
	return digits


def getFreq(x, n):
	s = ''
	for i in range(1, n + 1):
		s += str(x ** i)
	l = []
	for i in range(10):
		l.append(s.count(str(i)))
	return l


def getFreq(x, n):
	power_num = []
	result = []
	final = []
	for i in range(1, n + 1):
		power_num.append(x ** i)
	for i in power_num:
		while i > 0:
			last = i % 10
			result.append(last)
			i = i // 10
	result.sort()
	for i in range(10):
		final.append(result.count(i))
	return final


def getFreq(x, n):
	res = []
	for i in range(1, n + 1):
		res.append(x ** i)
	ans = [0] * 10
	for i in res:
		while i:
			ans[i % 10] += 1
			i //= 10
	return ans


def getFreq(x, n):
	s = ''
	p = []
	for index in range(n):
		s += str(x ** (index + 1))
	for index in range(10):
		p.append(s.count(str(index)))
	return p


def getFreq(x, n):
	l = []
	m = []
	for i in range(n):
		l.append(x ** (i + 1))
	c = a = 0
	for c in range(10):
		a = 0
		for i in l:
			while i > 0:
				s = i % 10
				if s == c:
					a += 1
				i = i // 10
		m.append(a)
	return m


def getFreq(x, n):
	l = []
	k = []
	for i in range(1, n + 1):
		l.append(str(x ** i))
	a = ''.join(l)
	for i in a:
		k.append(int(i))
	ans = []
	for i in range(10):
		ans.append(k.count(i))
	return ans


from collections import Counter

def getFreq(x, n):
	k = ''
	for i in range(1, n + 1):
		k += str(x ** i)
	c = []
	for i in range(10):
		c.append(k.count(str(i)))
	return c


def getFreq(x, n):
	int_str = ''
	for i in range(1, n + 1):
		int_str += str(x ** i)
	output = []
	for number in '0123456789':
		output.append(int_str.count(number))
	return output


def getFreq(x, n):
	s = ''
	for i in range(1, n + 1):
		s += str(x ** i)
	dic = {}
	l = []
	for i in s:
		if i not in dic:
			dic[i] = 1
		else:
			dic[i] += 1
	for i in range(10):
		if str(i) not in dic:
			l.append(0)
		else:
			l.append(dic[str(i)])
	return l


import math

def getFreq(x, n):
	ans = ''
	out = []
	for i in range(1, n + 1):
		ans += str(x ** i)
	for i in range(0, 10):
		out.append(ans.count(str(i)))
	return out


from collections import Counter

def getFreq(x, n):
	arr = []
	for i in range(1, n + 1):
		arr += [*str(x ** i)]
	c = Counter(arr)
	return [c[str(i)] for i in range(10)]


def getFreq(x, n):
	s = ''
	l = []
	for i in range(1, n + 1):
		s = s + str(x ** i)
	for i in range(10):
		if str(i) not in s:
			l.append(0)
		elif str(i) in s:
			a = s.count(str(i))
			l.append(a)
	return l


def getFreq(x, n):
	d = [0] * 10
	for j in range(1, n + 1):
		for k in str(x ** j):
			d[int(k)] += 1
	return d


def getFreq(x, n):
	exp = []
	digits = []
	res = []
	for i in range(1, n + 1):
		exp.append(x ** i)
	for i in range(len(exp)):
		temp = exp[i]
		while temp != 0:
			digits.append(temp % 10)
			temp = temp // 10
	for i in range(10):
		res.append(digits.count(i))
	return res


def getFreq(x, n):
	pows = []
	for i in range(1, n + 1):
		pows += list(str(x ** i))
	freq = {i: int(pows.count(str(i))) for i in range(10)}
	return freq.values()


def getFreq(x, n):
	arr = [0] * 10
	for i in range(1, n + 1):
		number = pow(x, i)
		while number:
			nu = number % 10
			arr[nu] += 1
			number = number // 10
	return arr


def getFreq(x, n):
	a = []
	for i in range(1, n + 1):
		z = str(x ** i)
		for j in z:
			a.append(int(j))
	c = []
	for i in range(10):
		z = a.count(i)
		c.append(z)
	return c


def getFreq(x, n):
	stri = ''
	list = []
	for i in range(1, n + 1):
		fact = x ** i
		stri = stri + str(fact)

	def cnt(num):
		return stri.count(str(num))
	list.append(cnt(0))
	list.append(cnt(1))
	list.append(cnt(2))
	list.append(cnt(3))
	list.append(cnt(4))
	list.append(cnt(5))
	list.append(cnt(6))
	list.append(cnt(7))
	list.append(cnt(8))
	list.append(cnt(9))
	return list


def getFreq(x, n):
	lis = []
	res = []
	for i in range(1, n + 1):
		lis.append(x ** i)
	for j in range(0, 10):
		count = 0
		for i in lis:
			m = str(i).count(str(j))
			count += m
		res.append(count)
	return res


def getFreq(x, n):
	nums = ''.join([str(pow(x, i)) for i in range(1, n + 1)])
	return [nums.count(str(i)) for i in range(10)]


def getFreq(x, n):
	freq = ''
	for i in range(1, n + 1):
		freq += str(pow(x, i))
	ans = []
	for i in range(10):
		ans.append(freq.count(str(i)))
	return ans


def getFreq(x, n):
	s = ''
	d = {}
	lst = []
	while n > 0:
		k = x ** n
		s = s + str(k)
		n = n - 1
	for i in s:
		if i in d:
			d[i] = d[i] + 1
		else:
			d[i] = 1
	for i in range(10):
		if str(i) in d.keys():
			lst.append(d[str(i)])
		else:
			lst.append(0)
	return lst


def a(l, n):
	while n:
		i = n % 10
		n = n // 10
		l[i] += 1
	return l

def getFreq(x, n):
	l = [0] * 10
	for i in range(1, n + 1):
		l = a(l, x ** i)
	return l


def getFreq(x, n):
	l = []
	ind = []
	for i in range(1, n + 1):
		l.append(x ** i)
	for i in range(0, 10):
		ind.append(0)
	for i in l:
		for j in str(i):
			ind[int(j)] = ind[int(j)] + 1
	return ind


def getFreq(x, n):
	s = ''
	for i in range(1, n + 1):
		s += str(x ** i)
	temp = []
	for i in range(10):
		if str(i) in s:
			temp.append(s.count(str(i)))
		else:
			temp.append(0)
	return temp


def getFreq(x, n):
	a = ''
	for i in range(n):
		a += str(x ** (i + 1))
	j = []
	for i in range(10):
		k = str(i)
		if k in a:
			j.append(a.count(k))
		else:
			j.append(0)
	return j


def getFreq(x, n):
	l = [x]
	for i in range(2, n + 1):
		l.append(l[-1] * x)
	d = {}
	for i in l:
		for j in str(i):
			try:
				d[j] += 1
			except:
				d[j] = 1
	l = [0 for i in range(10)]
	for i in d:
		l[int(i)] = d[i]
	return l


def getFreq(x, n):
	ls = [0] * 10
	for i in range(n):
		num = pow(x, i + 1)
		s = str(num)
		for j in range(len(s)):
			ls[int(s[j])] += 1
	return ls


def getFreq(x, n):
	l = [x ** i for i in range(1, n + 1)]
	arr = []
	for i in range(10):
		count = 0
		for j in l:
			count += str(j).count(str(i))
		arr.append(count)
	return arr


def getFreq(x, n):
	d = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0}
	for i in range(1, n + 1):
		t = pow(x, i)
		l = [int(x) for x in str(t)]
		for j in range(len(l)):
			d[l[j]] += 1
	return d.values()


def getFreq(x, n):
	ls = ''
	for i in range(1, n + 1):
		t = x ** i
		ls += str(t)
	k = {}
	for i in ls:
		if i not in k.keys():
			k[i] = 1
		else:
			k[i] += 1
	res = []
	for i in range(0, 10):
		if str(i) in k.keys():
			res.append(k[str(i)])
		else:
			res.append(0)
	return res


def getFreq(x, n):
	s1 = ''
	li = [0] * 10
	for i in range(1, n + 1):
		s1 = s1 + str(x ** i)
	for i in s1:
		li[int(i)] += 1
	return li