CF233B.Non-square Equation

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's consider 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.

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

我们考虑如下方程:

x2+s(x)⋅x−n=0,x^2 + s(x) \cdot x - n = 0,

其中 xx、nn 均为正整数,s(x)s(x) 表示 xx 在十进制下的各位数字之和。

给定一个整数 nn,请找出该方程的最小正整数解 xx;若不存在这样的解,则判定无解。

输入格式

A single line contains integer n (1 ≤ n ≤ 1018) — 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.

一行包含一个整数 nn(1≤n≤10181 \leq n \leq 10^{18})——方程的参数。

请注意,在 C++ 中读取或输出 64 位整数时,不要使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。

输出格式

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

如果方程没有正整数根,则输出 -1;否则,输出满足题中所给方程的最小正整数 xx(即 x>0x > 0)。

输入输出样例

  • 输入#1

    2

    输出#1

    1
  • 输入#2

    110

    输出#2

    10
  • 输入#3

    4

    输出#3

    -1

说明/提示

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

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

In the third test case the equation has no roots.

在第一个测试用例中,x=1x = 1 是最小的根。因为 s(1)=1s(1) = 1,且 12+1⋅1−2=01^2 + 1 \cdot 1 - 2 = 0。

在第二个测试用例中,x=10x = 10 是最小的根。因为 s(10)=1+0=1s(10) = 1 + 0 = 1,且 102+1⋅10−110=010^2 + 1 \cdot 10 - 110 = 0。

在第三个测试用例中,该方程无根。

输入解题思路,AI测评打分。不知道怎么写?

首页