Given a number N, the task is to check whether the number is Trimorphic number or not. A number is called Trimorphic number if and only if its cube ends in the same digits as the number itself. In other words, number appears at the end of its cube i.e let's say if the number of digits of N is k then the last k digit of the cube should be equal to N only.
Example 1:
Input: N = 1
Output: 1
Explaination: 1^{3} = 1. So the cube here is ending with 
the number.
Example 2:
Input: N = 2
Output: 0
Explaination: 2^{3} = 8. The cube is not ending with the 
number at it's end.
Example 3:
Input: N = 24
Output: 1
Explaination: 24^{3} = 13824. The cube is ending with 24.
Your Task:
You do not need to read input or print anything, Your task is to complete the function isTrimorphic() which takes N as input parameter and returns 1 if the number is trimorphic, otherwise, returns 0.
Expected Time Complexity: O(LogN)
Expected Auxiliary Space: O(1)
Constraints:
1 < N < 10000

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

Starter code:
#User function Template for python3



class Solution:

    def isTrimorphic(self, N):

        # code here

Solutions:
class Solution:

	def isTrimorphic(self, N):
		c = N ** 3
		t = str(N)
		s = str(c)
		if s[-len(t):] == t:
			return 1
		else:
			return 0


import math

class Solution:

	def isTrimorphic(self, N):
		if N == 0:
			return 1
		t = N * N * N
		dg = int(math.log10(N)) + 1
		if N == t % math.pow(10, dg):
			return 1
		return 0


class Solution:

	def isTrimorphic(self, N):
		l = len(str(N))
		cube = N ** 3
		return 1 if str(cube)[-l:] == str(N) else 0


class Solution:

	def isTrimorphic(self, N):
		cb = str(N ** 3)
		ln = len(str(N))
		if N == int(cb[-ln:]):
			return 1
		return 0


class Solution:

	def isTrimorphic(self, N):
		x = N ** 3
		x = str(x)[::-1]
		m = str(N)[::-1]
		for i in range(len(m)):
			if m[i] != x[i]:
				return 0
		return 1


class Solution:

	def isTrimorphic(self, N):
		x = N ** 3
		while N > 0:
			if N % 10 != x % 10:
				return 0
			x //= 10
			N //= 10
		return 1


class Solution:

	def isTrimorphic(self, N):
		x = pow(N, 3)
		x = str(x)
		ln = len(str(N))
		if N == int(x[-ln:]):
			return 1
		else:
			return 0


class Solution:

	def isTrimorphic(self, N):
		x = pow(N, 3)
		x = str(x)
		ln = len(str(N))
		if N == int(x[-ln:]):
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		p = str(N)
		q = N * N * N
		r = str(q)
		l = len(p)
		r = r[::-1]
		r = r[0:l]
		r = r[::-1]
		if p == r:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		a = N ** 3
		s = str(N)
		s1 = str(a)
		if s1.endswith(s):
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		n = str(N)
		l = len(n)
		N = N * N * N
		m = str(N)
		if n in m[-l:]:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		c = N * N * N
		while N > 0:
			if N % 10 != c % 10:
				return 0
			N = N // 10
			c = c // 10
		return 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		n1 = str(N)
		g = N * N * N
		s1 = str(g)
		l = len(n1)
		s1 = s1[::-1]
		s1 = s1[0:l]
		s1 = s1[::-1]
		if N == int(s1):
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		d = str(N ** 3)
		a = len(str(N))
		if d[-a:] == str(N):
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		n = str(N)
		a = pow(N, 3)
		s = str(a)
		l = len(n)
		s = s[::-1]
		s = s[0:l]
		s = s[::-1]
		if N == int(s):
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		temp = N
		b = str(pow(N, 3))
		if str(temp) in b:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		d = N ** 3
		e = str(N)
		g = len(e)
		h = str(d)
		n = len(h)
		h = h[n - g:]
		if e == h:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isTrimorphic(N))


class Solution:

	def isTrimorphic(self, N):
		ans = str(N * N * N)
		if str(N) in ans:
			return 1
		else:
			return 0


class Solution:

	def isTrimorphic(self, N):
		a = str(N ** 3)
		N = str(N)
		if N in a[-len(N):]:
			return 1
		else:
			return 0