Given N, check whether it is a Narcissistic number or not.
Note: Narcissistic Number is a number that is the sum of its own digits each raised to the power of the number of digits
 
Example 1:
Input:
N = 407
Output:
1
Explanation:
4^{3}+0^{3}+7^{3} = 64+0+343 
= 407 equals to N.
Example 2:
Input:
N = 111
Output:
0
Explanation:
1^{3}+1^{3}+1^{3} = 1+1+1
= 3 not equals to N.
Your Task:
You don't need to read input or print anything. Your task is to complete the function isNarcissistic() which takes an integer N as input parameters and returns an integer, 1 if N is a narcissistic number or 0 otherwise.
 
Expected Time Complexity: O(log N)
Expected Space Complexity: O(1)
 
Constraints:
1 <= N <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3

class Solution:

    def isNarcissistic(self, N):
        # code here

Solutions:
class Solution:

	def isNarcissistic(self, N):
		p = len(str(N))
		n = N
		sum = 0
		while N > 0:
			r = N % 10
			sum += r ** p
			N = N // 10
		if sum == n:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		td = 0
		num = N
		while num > 0:
			num = num // 10
			td += 1
		nn = 0
		num = N
		while num > 0:
			ld = num % 10
			nn += ld ** td
			num = num // 10
		if nn == N:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):

		def cube(n, l):
			return n ** l
		summ = 0
		for i in str(N):
			summ += cube(int(i), len(str(N)))
		if summ == N:
			return 1
		return 0


class Solution:

	def isNarcissistic(self, N):
		t = len(str(N))
		s = 0
		for i in str(N):
			s = s + int(i) ** t
		if s == N:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		N = str(N)
		ans = []
		for i in N:
			ans.append(int(i) ** len(N))
		if sum(ans) == int(N):
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		c = 0
		for i in str(N):
			c += int(i) ** len(str(N))
		if c == N:
			return 1
		return 0


class Solution:

	def isNarcissistic(self, N):
		d = str(N)
		length = len(d)
		pro = 0
		for i in d:
			pro = pro + pow(int(i), length)
		if pro == N:
			return 1
		else:
			return 0


import math

class Solution:

	def isNarcissistic(self, N):
		if N == 0:
			num_len = 0
		else:
			num_len = int(math.log10(N)) + 1
		wnum = N
		sum_powers = 0
		while wnum > 0:
			sum_powers += (wnum % 10) ** num_len
			wnum //= 10
		if sum_powers == N:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		x = 0
		y = str(N)
		for i in y:
			x += int(i) ** len(y)
		if x == N:
			return 1
		return 0


class Solution:

	def isNarcissistic(self, N):
		(res, x, m) = (0, N, len(str(N)))
		while N > 0:
			rem = N % 10
			res += rem ** m
			N //= 10
		return 1 if x == res else 0


class Solution:

	def isNarcissistic(self, N):
		sum = 0
		num_digits = len(str(N))
		list_n = [int(i) for i in str(N)]
		for num in list_n:
			sum += num ** num_digits
		if sum == N:
			return 1
		return 0


class Solution:

	def isNarcissistic(self, N):
		l = N
		sum = 0
		k = len(str(N))
		while l:
			d = l % 10
			sum = sum + d ** k
			l = l // 10
		if sum == N:
			return 1
		return 0


class Solution:

	def isNarcissistic(self, n):
		w = n
		o = n
		k = 0
		n = 0
		p = len(str(w))
		while w != 0:
			d = w % 10
			n = n + pow(d, p)
			w = w // 10
		if n == o:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		n = str(N)
		a = len(n)
		y = 0
		for x in n:
			y = y + int(x) ** a
		if y == N:
			return 1
		else:
			return 0


class Solution:

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


class Solution:

	def isNarcissistic(self, N):
		N = str(N)
		ans = []
		for i in N:
			ans.append(int(i) ** len(N))
		if sum(ans) == int(N):
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isNarcissistic(N))


class Solution:

	def isNarcissistic(self, N):
		s = str(N)
		d = len(s)
		e = N
		c = 0
		while e != 0:
			g = e % 10
			c += g ** d
			e = e // 10
		if N == c:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isNarcissistic(N))


class Solution:

	def isNarcissistic(self, N):
		c = len(str(N))
		temp = N
		sm = 0
		while N != 0:
			ld = N % 10
			sm += ld ** c
			N = N // 10
		if temp == sm:
			return 1
		return 0


class Solution:

	def isNarcissistic(self, N):
		N1 = str(N)
		n = len(N1)
		sum1 = 0
		for i in N1:
			sum1 = sum1 + int(i) ** n
		if sum1 == N:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		sum = 0
		num = N
		l = len(str(N))
		while num > 0:
			rem = (num % 10) ** l
			sum += rem
			num = num // 10
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		M = N
		D = N
		c = 0
		result = 0
		while M > 0:
			M = M // 10
			c += 1
		while N > 0:
			a = N % 10
			N = N // 10
			result = result + a ** c
		if result == D:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, N):
		p = str(N)
		l = len(p)
		s = 0
		for i in p:
			s += int(i) ** l
		if s == N:
			return 1
		return 0


class Solution:

	def isNarcissistic(self, N):
		le = len(str(N))
		n1 = N
		c = 0
		while N > 0:
			c += (N % 10) ** le
			N = N // 10
		return int(c == n1)


class Solution:

	def isNarcissistic(self, N):
		v = 0
		k = len(str(N))
		for i in str(N):
			v += pow(int(i), k)
		if v == N:
			return 1
		else:
			return 0


class Solution:

	def isNarcissistic(self, num):
		n = len(str(num))
		x = num
		c = 0
		for i in range(n):
			a = num % 10
			c += a ** n
			num = num // 10
		if c == x:
			return 1
		else:
			return 0


import math

class Solution:

	def isNarcissistic(self, N):
		sum1 = 0
		temp = N
		l = len(str(N))
		while N != 0:
			rem = N % 10
			sum1 = sum1 + math.pow(rem, l)
			N = N // 10
		if int(sum1) == temp:
			return 1
		else:
			return 0