301243: CF233B. Non-square Equation

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Non-square Equation

题意翻译

## 题目描述 让我们看看如下等式: $x^2+s(x)×x-n=0$ ,其中$x$ ,$n$ 是正整数,$s(x)$ 是函数,相当于求十进制中$x$ 的位数之和。 给出一个整数$n$ ,找到$x$ 的最小正整数根,或确定没有这样的根。 ## 输入输出格式 ### 输入格式: 只有一行,包括一个整数$n(1<=n<=10^{18})$ ,表示方程中的参数。 请不要在С++中使用%lld读取或写入64位整数。 最好使用cin,cout流或%I64d。 ### 输出格式: 输出使方程成立的最小正整数根$x(x>0)$ ,如果没有这样的根,则输出-1。 ## 说明 在第一组数据中,$x=1$ 是最小根。因为$s(1)=1$ 且$1^2+1×1-2=0$ 在第二组数据中,$x=10$ 是最小根。因为$s(10)=1+0=1$ 且$10^2+1×10-110=0$ 在第三组数据中,方程无根。 感谢@二元长天笑 提供的翻译

题目描述

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.

输入输出格式

输入格式


A single line contains integer $ n $ $ (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 $ x $ $ (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=1 $ is the minimum root. As $ s(1)=1 $ and $ 1^{2}+1·1-2=0 $ . In the second test case $ x=10 $ is the minimum root. As $ s(10)=1+0=1 $ and $ 10^{2}+1·10-110=0 $ . In the third test case the equation has no roots.

Input

题意翻译

## 题目描述 让我们看看如下等式: $x^2+s(x)×x-n=0$ ,其中$x$ ,$n$ 是正整数,$s(x)$ 是函数,相当于求十进制中$x$ 的位数之和。 给出一个整数$n$ ,找到$x$ 的最小正整数根,或确定没有这样的根。 ## 输入输出格式 ### 输入格式: 只有一行,包括一个整数$n(1<=n<=10^{18})$ ,表示方程中的参数。 请不要在С++中使用%lld读取或写入64位整数。 最好使用cin,cout流或%I64d。 ### 输出格式: 输出使方程成立的最小正整数根$x(x>0)$ ,如果没有这样的根,则输出-1。 ## 说明 在第一组数据中,$x=1$ 是最小根。因为$s(1)=1$ 且$1^2+1×1-2=0$ 在第二组数据中,$x=10$ 是最小根。因为$s(10)=1+0=1$ 且$10^2+1×10-110=0$ 在第三组数据中,方程无根。 感谢@二元长天笑 提供的翻译

加入题单

算法标签: