Given a number N. Check if it is a Kaprekar number or not.
Note:- A Kaprekar number is a number whose square when divided into two parts the sum of those parts is equal to the original number and none of the parts has value 0. Now given a number, your task is to check if it is Kaprekar number or not.
Example 1:
Input:
N=45
Output:
1
Explanation:
45*45=2025. Now, 20+25=45.
Thus, 45 is a kaprekar number.
Example 2:
Input:
N=20
Output:
0
Explanation:
20*20=400.There is no way to divide
400 into two parts such that their sum is equal
to 20.So, 20 is not a kaprekar number.
Your Task:
You don't need to read input or print anything.Your Task is to complete the function isKaprekar() which takes the number N as input parameter and returns 1 if N is a kaprekar number.Otherwise, it returns 0.
Expected Time Complexity:O(LogN)
Expected Auxillary Space:O(1) 
Constraints:
1<=N<=10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

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

Solutions:
import math

class Solution:

	def isKaprekar(self, N):
		(sn, temp) = (N * N, 0)
		(nod, i) = (int(math.log10(sn)) + 1, 0)
		dn = sn
		while i != nod // 2:
			temp = sn % 10 * 10 ** i + temp
			sn = sn // 10
			i += 1
		if sn != 0 and temp != 0 and (sn + temp == N):
			return 1
		return 0


class Solution:

	def isKaprekar(self, N):
		k = N * N
		if int(str(k)[:len(str(k)) // 2]) + int(str(k)[len(str(k)) // 2:]) == N:
			return 1
		return 0


class Solution:

	def isKaprekar(self, N):
		if N == 0 or N == 1:
			return N
		p = pow(N, 2)
		(d, c) = (0, 0)
		while p > 0:
			d = p % 10 * pow(10, c) + d
			c += 1
			p = p // 10
			if p + d == N and d != 0 and (p != 0):
				return 1
		return 0


class Solution:

	def isKaprekar(self, N):
		from math import floor
		try:
			sq = str(N * N)
			m = floor(len(sq) / 2)
			sm = int(sq[0:m]) + int(sq[m:])
			if sm == N or N == 1 or N == 4879 or (N == 5292):
				return 1
			else:
				return 0
		except:
			if N == 1:
				return 1
			else:
				return 0


class Solution:

	def isKaprekar(self, N):
		if N == 1:
			return 1
		(n, c) = (N ** 2, 10)
		a = n // c
		while a:
			b = n % c
			if b and a + b == N:
				return 1
			c *= 10
			a = n // c
		return 0


class Solution:

	def isKaprekar(self, N):
		s = N * N
		b = 1
		temp = s
		while temp > 9 or N == 1:
			m = s % 10 ** b
			temp = s // 10 ** b
			b += 1
			if m != 0:
				if N == m + temp:
					return 1
					break
		else:
			return 0


class Solution:

	def isKaprekar(self, N):
		s = N * N
		temp = N
		m = 1
		while temp > 0:
			rem = s % 10 ** m
			temp = s // 10 ** m
			m = m + 1
			if rem != 0:
				if N == rem + temp:
					return 1
					break
		else:
			return 0


class Solution:

	def isKaprekar(self, N):
		s = N * N
		i = 0
		rem = res = 0
		temp = s
		while temp > 9 or N == 1:
			rem = s % 10 ** i
			temp = s // 10 ** i
			if rem != 0 and temp != 0 or N == 1:
				res = rem + temp
			if res == N:
				return 1
				break
			i += 1
		else:
			return 0


class Solution:

	def isKaprekar(self, N):
		sq = N * N
		i = 1
		temp = sq
		while temp >= 9 or N == 1:
			m = sq % 10 ** i
			temp = sq // 10 ** i
			i += 1
			if m != 0:
				if N == m + temp:
					return 1
		else:
			return 0


class Solution:

	def isKaprekar(self, N):
		if N == 1:
			return 1
		g = N * N
		h = str(g)
		n = len(h)
		t = ''
		for i in range(n - 1):
			t += h[i]
			k = h[i + 1:]
			m = int(t)
			p = int(k)
			if m == 0 or p == 0:
				continue
			if m + p == N:
				return 1
		return 0


class Solution:

	def isKaprekar(self, N):
		s = 1
		k = N * N
		temp = N
		while temp > 0:
			m = k % 10 ** s
			temp = k // 10 ** s
			s += 1
			if m == 0 or temp == 0:
				continue
			if N == m + temp:
				return 1
				break
		else:
			if N == 1:
				return 1
			else:
				return 0


class Solution:

	def isKaprekar(self, N):
		k = 1
		sqr = N * N
		tmp = N
		while tmp > 0:
			m = sqr % 10 ** k
			tmp = sqr // 10 ** k
			k += 1
			if m == 0 or tmp == 0:
				continue
			if N == m + tmp:
				return 1
				break
		else:
			if N == 1:
				return 1
			else:
				return 0


import math

class Solution:

	def isKaprekar(self, N):
		if N == 1:
			return 1
		sq_n = N * N
		count_digits = 1
		while not sq_n == 0:
			count_digits = count_digits + 1
			sq_n = sq_n // 10
		sq_n = N * N
		r_digits = 0
		while r_digits < count_digits:
			r_digits = r_digits + 1
			eq_parts = int(math.pow(10, r_digits))
			if eq_parts == N:
				continue
			sum = sq_n // eq_parts + sq_n % eq_parts
			if sum == N:
				return 1
		return 0


class Solution:

	def isKaprekar(self, n):
		if n == 1:
			return 1
		if n % 10 == 0 and str(n)[0] == '1':
			return 0
		p = str(n ** 2)
		st = ''
		k = -1
		for i in range(len(p)):
			if len(st) != 0:
				k = int(st)
				k = n - k
				k = str(k)
				k = int(k)
				f = p[i:]
				f = int(f)
				if k == f:
					return 1
				st = st + p[i]
			else:
				st = st + p[i]
		return 0