P15209 [GeeksforGeeks] Find the smallest root of the equation x2 sxx n0 where sx is the sum of digits of root x2219
普及-
题目描述

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}

输入格式

见题面

输出格式

见题面

样例输入
n = 110
样例输出
10