• odeforces Round #144 (Div. 2) B


    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 }
  • 相关阅读:
    python基础 2
    python基础 1
    进程
    进程作业
    上海python14期第二次阶段性考试
    面向对向之元类
    面向对向
    笔试题
    模块(2)
    模块作业
  • 原文地址:https://www.cnblogs.com/Missa/p/2721823.html
Copyright © 2020-2023  润新知