You are given an integer n, find the smallest positive integer root of equation x, or else print -1 if no roots are found.
Equation: x^2+s(x)*x-n=0
where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.
 
Example 1:
Input: n = 110
Output: 10
Explanation: x=10 is the minimum root. 
As s(10)=1+0=1 and 102+1*10-110=0.
Example 2:
Input: n = 5
Output: -1
Explanation: There is no x possible which
satisfy the above equation.
 
Your Task:
You don't need to read or print anything. Your task is to complete the function Root() which takes n as input parameter and retuns the minimum root of the given equation. If not possible returns -1.
 
Expected Time Complexity: O(k) where k is constant
Expected Space Complexity: O(1)
 
Constraints:
1 <= n <= 10^{18}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
	def Root(self, n):
		# Code here

Solutions:
import math

class Solution:

	def summation(self, x):
		temp = 0
		while x > 0:
			temp += x % 10
			x //= 10
		return temp

	def roots(self, a, b, c):
		y = b * b - 4 * a * c
		if y < 0:
			return -1
		ok = (-b + math.sqrt(y)) / (2 * a)
		if int(ok) == ok:
			if ok > 0:
				return int(ok)
			else:
				return -1
		return -1

	def Root(self, x):
		root = 999999999999
		flag = 0
		for i in range(0, 91):
			temp = self.roots(1, i, -x)
			if temp != -1:
				if self.summation(temp) == i:
					if temp < root:
						root = temp
						flag = 1
		if flag:
			return root
		else:
			return -1