http://codeforces.com/contest/233/problem/B

s(x)最大为81.所以x*(x+s(x))==n假如有x存在,则x必然小于sqrt(n)。且大于sqrt(n)-82。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cmath>
 6 
 7 using namespace std;
 8 
 9 long long n,ans;
10 
11 int getsum(long long x)
12 {
13     int s=0;
14     while(x)
15     {
16         s+=x%10;
17         x/=10;
18     }
19     return s;
20 }
21 
22 int main()
23 {
24     while(~scanf("%I64d",&n))
25     {
26         ans=-1;
27         long long tmp=(long long ) sqrt(n);
28         long long i=(tmp-82>0?tmp-82:1);
29         for(;i<=tmp;i++)
30             if(i*i+i*getsum(i)==n)
31             {
32                 ans=i;
33                 break;
34             }
35         printf("%I64d\n",ans);
36     }
37     return 0;
38 }

相关文章:

  • 2021-11-29
  • 2021-08-08
  • 2021-10-25
  • 2021-12-13
  • 2022-01-04
  • 2022-01-12
  • 2022-01-25
  • 2021-12-08
猜你喜欢
  • 2022-03-01
  • 2021-09-12
  • 2021-08-15
  • 2021-10-28
  • 2021-10-18
  • 2021-08-05
  • 2021-09-03
相关资源
相似解决方案