Given two positive numbers X and Y, check if Y is a power of X or not.
 
Example 1:
Input:
X = 2, Y = 8
Output:
1
Explanation:
2^{3} is equal to 8.
 
Example 2:
Input:
X = 1, Y = 8
Output:
0
Explanation:
Any power of 1 is not 
equal to 8.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function isPowerOfAnother() which takes an integer and returns 1 if y is the power of x, else return 0.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints: 
1 <= x <= 10^{3}
1 <= y <= 10^{8}

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:

    def isPowerOfAnother (ob,X,Y):

        # code here 

Solutions:
from math import pow, log

class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 0 or X == 1:
			return 0
		else:
			m = log(Y, X)
			m = round(m)
			if X ** m == Y:
				return 1
			return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		for i in range(0, Y):
			if pow(X, i) == Y:
				return 1
		return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 1:
			return 0
		elif Y == 1:
			return 1
		else:
			while Y % X == 0:
				Y = Y // X
			if Y == 1:
				return 1
			return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		a = 0
		p = 0
		if X != 1:
			while a <= Y:
				a = pow(X, p)
				if a == Y:
					return 1
				p += 1
			return 0
		return 0


class Solution:

	def isPowerOfAnother(self, x, y):
		if x == 1:
			if y == 1:
				return 1
			if y != 1:
				return 0
		return self.isPower(x, y)

	def isPower(self, x, y):
		if y == 1:
			return 1
		if y % x != 0:
			return 0
		return self.isPower(x, y / x)


class Solution:

	def isPowerOfAnother(ob, X, Y):
		for i in range(0, Y + 1):
			p = X ** i
			if p > Y or (i >= Y and p < Y):
				return 0
			elif p == Y:
				break
		return 1


from math import log

class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 1:
			if Y == 1:
				return 1
			return 0
		c = log(Y) / log(X)
		return 1 if int(c) == c else 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		if Y == 1 or X == Y or (X == 1 and Y == 1):
			return 1
		if X == 1 or Y < X:
			return 0
		for i in range(2, Y):
			if X ** i == Y:
				return 1
			if X ** i > Y:
				return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		if Y == 1:
			return 1
		else:
			for i in range(int(Y)):
				if X ** i == Y:
					return 1
			return 0


import math

class Solution:

	def isPowerOfAnother(ob, X, Y):
		for i in range(0, math.ceil(math.sqrt(Y)) + 1):
			if X ** i == Y:
				return 1
		return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		import math
		for index in range(0, math.ceil(Y / 2) + 1):
			if pow(X, index) == Y:
				return 1
		return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 1 and Y != 1:
			return 0
		res = 0
		p = 0
		while res <= Y:
			res = pow(X, p)
			if res == Y:
				return 1
			p += 1
		return 0


import math

class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 1 and Y == 1:
			return 1
		elif X == 1 and Y != 1:
			return 0
		else:
			pass
		num = int(math.log(Y, X))
		if X ** num == Y:
			return 1
		return 0


import math

class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 1:
			return 0
		else:
			ans = math.log(Y) / math.log(X)
			if math.floor(ans) == math.ceil(ans):
				return 1
			else:
				return 0


class Solution:

	def isPowerOfAnother(ob, x, y):
		if x == 1:
			return 0
		while y > 1:
			if y % x != 0:
				return 0
			y = y // x
		return 1


class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 0 or X == 1:
			return 0
		if Y == 1:
			return 1
		while True:
			new = int(Y // X)
			if new * X != Y:
				return 0
			else:
				Y = new
			if new == 1:
				return 1


class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 1 and Y == 1:
			return 1
		if X == 1:
			return 0
		if Y == 1:
			return 1
		i = 1
		while i <= Y:
			i = i * X
			if i == Y:
				return 1
		return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X == 1:
			if Y == 1:
				return 1
			return 0
		for i in range(100000):
			z = X ** i
			if z == Y:
				return 1
			elif z > Y:
				return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		for i in range(0, Y // 2 + 1):
			if X ** i == Y:
				return 1
				break
		return 0


from math import log

class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X in [1, 0]:
			return int(X == Y)
		pw = int(log(Y, X))
		return int(pow(X, pw) == Y)


import math

class Solution:

	def isPowerOfAnother(ob, X, Y):
		j = 0
		while j < Y and X ** j <= Y:
			if X ** j == Y:
				return 1
			j = j + 1
		return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		flag = 0
		for i in range(Y):
			if X ** i == Y:
				flag = 1
				break
		if flag == 1:
			return 1
		else:
			return 0


import math

class Solution:

	def isPowerOfAnother(ob, X, Y):
		try:
			p = math.log(Y, X)
			if math.ceil(p) == math.floor(p):
				return 1
			else:
				return 0
		except ZeroDivisionError:
			return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		i = 2
		a = X
		if X != 1 and X != 0:
			while a < Y:
				a = X ** i
				i += 1
			if a == Y or Y == 1:
				return 1
			else:
				return 0
		else:
			return 0


import math

class Solution:

	def isPowerOfAnother(ob, X, Y):
		if X <= 1:
			return 0
		t = math.log(Y, X)
		if t - int(t) == 0:
			return 1
		else:
			return 0


import math

class Solution:

	def isPowerOfAnother(ob, X, Y):
		if Y == 1:
			return 1
		for i in range(1, Y):
			if math.pow(X, i) == Y:
				return 1
		else:
			return 0


class Solution:

	def isPowerOfAnother(ob, X, Y):
		a = X
		b = Y
		c = b // a
		if Y == 1:
			return 1
		if X == 1 and Y == 1:
			return 1
		if X == 1 and Y != 1:
			return 0
		if b % a != 0:
			return 0
		while c != 1:
			b = c
			c = b // a
			if b % a != 0:
				return 0
		return 1


class Solution:

	def isPowerOfAnother(ob, X, Y):
		import math
		try:
			ans = math.log(Y) / math.log(X)
			if ans.is_integer():
				return 1
			else:
				return 0
		except:
			return 0


class Solution:

	def isPowerOfAnother(self, X, Y):
		if Y == 1:
			return 1
		elif X == 1 and Y != 1:
			return 0
		temp = X
		while temp <= Y:
			if temp == Y:
				return 1
			temp *= X
		return 0


class Solution:

	def isPowerOfAnother(self, X, Y):
		if X == 1:
			return 0
		if Y == 1:
			return 1
		elif Y % X:
			return 0
		return self.isPowerOfAnother(X, Y // X)


class Solution:

	def isPowerOfAnother(ob, X, Y):
		from math import log, floor, ceil
		if X == 1:
			return 0
		h = log(Y) / log(X)
		if floor(h) == ceil(h):
			return 1
		return 0