CF233B.Non-square Equation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's consider equation:

x2+s(x)xn=0,x^{2}+s(x)·x-n=0, where x,nx,n are positive integers, s(x)s(x) is the function, equal to the sum of digits of number xx in the decimal number system.

You are given an integer nn , find the smallest positive integer root of equation xx , or else determine that there are no such roots.

输入格式

A single line contains integer nn (1<=n<=1018)(1<=n<=10^{18}) — the equation parameter.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

输出格式

Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer xx (x>0)(x>0) , that the equation given in the statement holds.

输入输出样例

  • 输入#1

    2
    

    输出#1

    1
    
  • 输入#2

    110
    

    输出#2

    10
    
  • 输入#3

    4
    

    输出#3

    -1
    

说明/提示

In the first test case x=1x=1 is the minimum root. As s(1)=1s(1)=1 and 12+112=01^{2}+1·1-2=0 .

In the second test case x=10x=10 is the minimum root. As s(10)=1+0=1s(10)=1+0=1 and 102+110110=010^{2}+1·10-110=0 .

In the third test case the equation has no roots.

首页