> 文档中心 > CF233B Non-square Equation

CF233B Non-square Equation


📋 个人简介

🎉大家好,我是3月份新人榜排名第三的 ༺Blog༒Hacker༻
💬支持我:点赞👍+收藏⭐️+留言📝
🌺格言:༺永做优质༒programmer༻

注(具体请见CF665B Shopping):

我的更新时间主要在每周4、(5)、6.
更新内容会偏向英文题目
CFUVA为主
同时,感谢洛谷提供的翻译

📣Non-square Equation

🔥题目描述
❄️Let’s consider equation:

❄️ x 2 + s ( x ) ⋅ x − n = 0 x^2+s(x)⋅x−n=0 x2+s(x)xn=0, where x , n x,n x,n are positive integers, s ( x ) s(x) s(x) is the function, equal to the sum of digits of number x x x in the decimal number system.

❄️You are given an integer n n n , find the smallest positive integer root of equation x x x , or else determine that there are no such roots.
🔥输入格式
❄️A single line contains integer n ( 1 < = n < = 1 0 18 ) n (1<=n<=10^{18}) 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.
🔥输出格式
❄️Print -1, if the equation doesn’t have integer positive roots. Otherwise print such smallest integer x ( x > 0 ) x (x>0) x(x>0) , that the equation given in the statement holds.
CF233B Non-square Equation

🔥说明/提示
❄️In the first test case x = 1 x=1 x=1 is the minimum root. As s ( 1 ) = 1 s(1)=1 s(1)=1 and 1 2 + 1 ⋅ 1 − 2 = 0 1^{2}+1·1-2=0 12+112=0

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

❄️In the third test case the equation has no roots.
🔥说明翻译
❄️在第一组数据中, x = 1 x=1 x=1最小根。因为 s ( 1 ) = 1 s(1)=1 s(1)=1 and 1 2 + 1 ⋅ 1 − 2 = 0 1^{2}+1·1-2=0 12+112=0

❄️在第二组数据中, x = 10 x=10 x=10是最小根。因为 s ( 10 ) = 1 + 0 = 1 s(10)=1+0=1 s(10)=1+0=1 and 1 0 2 + 1 ⋅ 10 − 110 = 0 10^{2}+1·10-110=0 102+110110=0.

❄️在第三组数据中,方程无根。

🔥输入输出样例

❄️输入 #12❄️输出 #11❄️输入 #2110❄️输出 #210❄️输入 #34❄️输出 #3-1

💯AC CODE

#include#define int long long //与signed main()连用 using namespace std;int n;int s(int x){int sum=0;while(x){sum+=x%10;x/=10;}return sum; }signed main()//防止报错 {cin>>n;for(int i=max((double)sqrt(n)-81,(double)1);i<=sqrt(n);++i){if((i*i)+s(i)*i==n){ cout<<i;return 0; }}cout<<"-1"; return 0;}

🔮朋友们,点赞收藏是我更新的动力,明天再见,拜拜!!!

NICE