Given a number N, find if it is Disarium or not. A number is called Disarium if sum of its digits powered with their respective positions is equal to the number itself. Output 1 if it's Disarium, and 0 if not.
 
Example 1:
Input:
N = 89
Output:
1
Explanation:
8^1+9^2 = 89 thus output is 1.
Example 2:
Input:
N = 81
Output:
0
Explanation:
8^1+1^2 = 9 thus output is 0. 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function isDisarium() which takes an Integer N as input and returns the answer.
 
Expected Time Complexity: O(log(N))
Expected Auxiliary Space: O(1)
 
Constraints:
0 <= N <= 10^{8}

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

Starter code:
#User function Template for python3

class Solution:
    def isDisarium(self, N):
        # code here 

Solutions:
class Solution:

	def isDisarium(self, N):
		summ = 0
		k = 1
		for i in str(N):
			summ += int(i) ** k
			k += 1
		if summ == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		N = str(N)
		x = 0
		for i in range(len(N)):
			x += int(N[i]) ** (i + 1)
		if x == int(N):
			return 1
		return 0


class Solution:

	def isDisarium(self, n):
		m = n
		count = 0
		while m:
			count += 1
			m = m // 10
		k = n
		num = 0
		while k:
			l = k % 10
			num += l ** count
			count -= 1
			k = k // 10
		return 1 if n == num else 0


class Solution:

	def isDisarium(self, N):
		l = [i for i in str(N)]
		c = 0
		for i in range(1, len(l) + 1):
			c += pow(int(l[i - 1]), i)
		if N == c:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		n = str(N)
		a = 0
		sum = 0
		for i in range(len(n)):
			a = pow(int(n[i]), i + 1)
			sum = sum + a
		if sum == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		y = 0
		x = N
		sum = 0
		for i in range(len(str(N))):
			y = x % 10
			sum += y ** len(str(x))
			x = x // 10
		if sum == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		count = len(str(N))
		sum = 0
		x = N
		while x != 0:
			r = x % 10
			sum = int(sum + pow(r, count))
			count = count - 1
			x = x // 10
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def digitCount(self, num, count):
		if num == 0:
			return count
		else:
			count += 1
			return self.digitCount(num // 10, count)

	def Calcsum(self, num, digit):
		if num == 0:
			return 0
		else:
			return pow(num % 10, digit) + self.Calcsum(num // 10, digit - 1)

	def isDisarium(self, N):
		count = 0
		totdigit = self.digitCount(N, count)
		x = self.Calcsum(N, totdigit)
		if N == x:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		temp = N
		sume = 0
		x = len(str(N))
		while int(N) != 0:
			d = int(N) % 10
			N = int(N) // 10
			sume += pow(d, x)
			x -= 1
		if sume == temp:
			return 1
		else:
			return 0


def countd(num, count):
	if num == 0:
		return count
	else:
		count += 1
		return countd(num // 10, count)

def calcsum(num, count):
	if num == 0:
		return 0
	else:
		return pow(num % 10, count) + calcsum(num // 10, count - 1)

class Solution:

	def isDisarium(self, N):
		count = countd(N, 0)
		num1 = calcsum(N, count)
		if num1 == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		power = 1
		sum1 = 0
		for i in str(N):
			sum1 = sum1 + int(i) ** power
			power += 1
		if sum1 == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		n = N
		num_digits = 0
		while n > 0:
			num_digits += 1
			n //= 10
		n = N
		sum1 = 0
		while n > 0:
			digit = n % 10
			sum1 += digit ** num_digits
			num_digits -= 1
			n //= 10
		if N == sum1:
			return 1
		else:
			return 0


import math

class Solution:

	def isDisarium(self, N):
		x = N
		sum = 0
		length = len(str(N))
		while x != 0:
			temp = x % 10
			sum = sum + math.pow(temp, length)
			length -= 1
			x = x // 10
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		ans = 0
		n = len(str(N))
		a = str(N)

		def sol(ans, i):
			if i == n:
				return 0
			return ans + int(a[i]) ** (i + 1) + sol(ans, i + 1)
		return int(N == sol(0, 0))


class Solution:

	def isDisarium(self, N):

		def rec(new, leng, sum):
			if sum == N and new == 0:
				return 1
			if new == 0 or leng < 0:
				return 0
			rem = new % 10
			new = new // 10
			sum += rem ** leng
			return rec(new, leng - 1, sum)
		s = str(N)
		leng = len(s)
		return rec(N, leng, 0)


class Solution:

	def isDisarium(self, N):
		sum = 0
		s = [int(x) for x in str(N)]
		k = len(s)
		for i in range(0, k):
			sum = sum + s[i] ** (i + 1)
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, n):
		p = n
		s = 0
		i = len(str(n))
		while n > 0:
			a = n % 10
			k = pow(a, i)
			i -= 1
			s = s + k
			n = n // 10
		if s == p:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		su = 0
		l = []
		a = N
		while N > 0:
			l.append(N % 10)
			N = N // 10
		l = l[::-1]
		for i in range(len(l)):
			su = su + l[i] ** (i + 1)
		if su == a:
			return 1
		else:
			return 0


class Solution:

	def check(self, l, i, n, sum):
		if sum == int(l):
			return 1
		if i == n:
			return 0
		sum += int(l[i]) ** (i + 1)
		return self.check(l, i + 1, n, sum)

	def isDisarium(self, N):
		s = str(N)
		return self.check(s, 0, len(s), 0)


class Solution:

	def isDisarium(self, N):
		ans = 0
		a = str(N)
		for i in range(len(str(N))):
			ans += int(a[i]) ** (i + 1)
		return int(N == ans)


class Solution:

	def solve(self, n, i, s):
		if s == int(n):
			return 1
		if i == len(n):
			return 0
		return self.solve(n, i + 1, s + int(n[i]) ** (i + 1))

	def isDisarium(self, N):
		return self.solve(str(N), 0, 0)


import math

class Solution:

	def isDisarium(self, N):

		def length(N):
			c = 0
			while N != 0:
				c += 1
				N = N // 10
			return c
		l = length(N)
		(dn, s) = (N, 0)
		while dn > 0:
			s += math.pow(dn % 10, l)
			dn = dn // 10
			l -= 1
		if s == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		r = N
		s = len(str(N))
		sum = 0
		while N > 0:
			d = N % 10
			sum = sum + d ** s
			s -= 1
			N //= 10
		if sum == r:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		b = N
		a = 0
		s = len(str(N))
		c = 0
		while N > 0:
			r = N % 10
			c = c + r ** s
			s = s - 1
			N = N // 10
		if b == c:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		s = str(N)
		r = len(s) - 1
		i = 0
		d = 0
		while i <= r:
			p = s[i]
			p = int(p)
			i = i + 1
			p = p ** i
			d = d + p
		if d == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		ans = 0
		li = []
		temp = N
		while N:
			d = N % 10
			N = N // 10
			li.append(d)
		x = 1
		for i in range(len(li) - 1, -1, -1):
			ans += li[i] ** x
			x += 1
		if ans == temp:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		Nn = list(str(N))
		m = list(map(int, Nn))
		t = 0
		for i in range(len(m)):
			t += m[i] ** (i + 1)
		if t == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		(k, res, x) = (len(str(N)), 0, N)
		for i in range(k, 0, -1):
			rem = N % 10
			res += pow(rem, i)
			N //= 10
		return 1 if res == x else 0


class Solution:

	def isDisarium(self, N: int) -> int:
		number = N
		exponent = len(str(N))
		result = 0
		while number:
			result += (number % 10) ** exponent
			exponent -= 1
			number //= 10
		return 1 if result == N else 0


class Solution:

	def isDisarium(self, N):
		number = N
		length = len(str(N))
		ans = 0
		while N != 0:
			digit = N % 10
			N = N // 10
			ans += digit ** length
			length -= 1
		if ans == number:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		a = 0
		b = 1
		n = str(N)
		for x in n:
			a = a + int(x) ** b
			b += 1
		if a == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		s = 0
		n = str(N)
		for i in range(len(n)):
			s = s + int(n[i]) ** (i + 1)
		if s == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		sum = 0
		j = 1
		s = str(N)
		for i in s:
			sum += pow(int(i), j)
			j += 1
		if sum == N:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		n = str(N)
		rn = ''.join(reversed(n))
		x = int(rn)
		s = 0
		i = 1
		while x != 0:
			r = x % 10
			s = s + pow(r, i)
			i = i + 1
			x = x // 10
		if s == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		s = 0
		N = str(N)
		for i in range(len(N)):
			a = N[i]
			b = int(a) ** (i + 1)
			s += b
		if s == int(N):
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		s = list(map(lambda x: int(x), str(N)))
		total = 0
		for itr in range(len(s)):
			total += s[itr] ** (itr + 1)
		return 1 if total == N else 0


class Solution:

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


class Solution:

	def isDisarium(self, N):
		sum = 0
		j = 1
		s = str(N)
		for i in s:
			sum = sum + pow(int(i), j)
			j = j + 1
		if sum == N:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isDisarium(N))


class Solution:

	def isDisarium(self, N):
		k = str(N)
		k = len(k)
		u = N
		sum = 0
		while N != 0:
			r = N % 10
			sum = sum + r ** k
			k -= 1
			N = N // 10
		if sum == u:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isDisarium(N))


class Solution:

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


class Solution:

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


class Solution:

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


class Solution:

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


class Solution:

	def isDisarium(self, N):
		digits = [int(d) for d in str(N)]
		digit_sum = 0
		for i in range(len(digits)):
			digit_sum += digits[i] ** (i + 1)
		return 1 if digit_sum == N else 0


class Solution:

	def isDisarium(self, N):
		l = []
		s = 0
		k = []
		temp = N
		while N:
			i = N % 10
			N = N // 10
			l.append(i)
		l = l[::-1]
		for i in range(len(l)):
			s = l[i] ** (i + 1)
			k.append(s)
		if sum(k) == temp:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		copy = N
		s = str(N)
		x = 0
		n = len(s)
		for i in range(len(s)):
			x += pow(N % 10, n - i)
			N = N // 10
		if x == copy:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		s = 0
		c = 1
		for i in str(N):
			m = int(i) ** c
			s += m
			c += 1
		return 1 if N == s else 0


import math

class Solution:

	def isDisarium(self, N):
		N = str(N)
		s = 0
		for i in range(len(N)):
			s = s + math.pow(int(N[i]), i + 1)
		if int(s) == int(N):
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		l = list(str(N))
		s = 0
		for x in range(len(l)):
			s += int(l[x]) ** (x + 1)
		if s == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		p = str(N)
		s = 0
		r = N
		w = len(p)
		while N != 0:
			d = N % 10
			s = s + int(pow(d, w))
			w = w - 1
			N = N // 10
		if r == s:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		a = 0
		s = str(N)
		for i in range(len(s)):
			x = i + 1
			a += pow(int(s[i]), x)
		if a == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		(s, p, j) = (0, 0, 1)
		h = N
		while N > 0:
			s = 10 * s + N % 10
			N //= 10
		while s > 0:
			p += (s % 10) ** j
			j += 1
			s //= 10
		return 1 if h == p else 0


class Solution:

	def isDisarium(self, N):
		S = str(N)
		count = len(S)
		marker = count - 1
		new_N = 0
		while count > 0:
			new_N += int(S[marker]) ** count
			count -= 1
			marker -= 1
		if new_N == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		self.N = N
		count = 0
		j = 1
		for i in str(self.N):
			count += int(i) ** j
			j += 1
		if count == self.N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, n):
		x = str(n)
		x = [int(i) for i in x]
		k = 0
		for i in range(len(x)):
			k += x[i] ** (i + 1)
		if k == n:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		sum = 0
		num = str(N)
		for j in range(len(num)):
			sum += int(num[j]) ** (j + 1)
		if sum == N:
			return 1
		else:
			return 0


import math

class Solution:

	def isDisarium(self, N):
		R = str(N)
		l = [int(i) for i in R]
		sum = 0
		for i in range(len(l)):
			sum = int(sum + math.pow(l[i], i + 1))
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		sum = 0
		power = 1
		for i in str(N):
			sum += pow(int(i), power)
			power += 1
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		s = 0
		for (p, i) in enumerate(str(N)):
			s += int(i) ** (p + 1)
		if s == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		s = str(N)
		n = len(s)
		res = 0
		t = N
		for i in range(n, 0, -1):
			res += (N % 10) ** i
			N = N // 10
		if res == t:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		l = []
		a = str(N)
		for i in range(1, len(a) + 1):
			l.append(int(a[i - 1]) ** i)
			p = sum(l)
		if p == N:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		x = 0
		y = N
		z = len(str(N))
		while N > 0:
			a = N % 10
			x = x + pow(a, z)
			N = N // 10
			z = z - 1
		if x == y:
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		total_sum = 0
		position = 1
		for digit in str(N):
			total_sum += pow(int(digit), position)
			position += 1
		return 1 if total_sum == N else 0


class Solution:

	def isDisarium(self, N):
		s_num = str(N)
		c = len(s_num)
		sum1 = 0
		dup = N
		while N != 0:
			sum1 += pow(N % 10, c)
			N = N // 10
			c -= 1
		if sum1 == dup:
			return 1
		return 0


class Solution:

	def isDisarium(self, N):
		N = str(N)
		sum = 0
		for (idx, i) in enumerate(N):
			sum += int(i) ** (idx + 1)
		if sum == int(N):
			return 1
		else:
			return 0


class Solution:

	def isDisarium(self, N):
		h = 0
		j = N
		a = N
		z = str(N)
		z = list(z)
		b = len(z)
		while N != 0:
			a = N % 10
			h = h + a ** b
			N = N // 10
			b = b - 1
		if j == h:
			return 1
		return 0