HDU 5752 Sqrt Bo(水~)

来源:互联网 发布:半熟鸡蛋 知乎 编辑:程序博客网 时间:2024/06/07 19:42

Description
定义这里写图片描述,求最小的y使得这里写图片描述,其中这里写图片描述
Input
多组用例,每组用例输入一个非负整数n(n<10^100),以文件尾结束输入,用例不超过120组
Output
对于每组用例,如果y<=5则输出y,否则输出“TAT”
Sample Input
233
233333333333333333333333333333333333333333333333333333333
Sample Output
3
TAT
Solution
满足条件的n最大不超过2^31-1,故若串长大于12的时候输出TAT,否则将串存在一个long long里,对其开五次平方判断即可
Code

#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;typedef long long ll;#define maxn 111char s[maxn];int main(){    while(~scanf("%s",s))    {        int len=strlen(s);        if(len>12)printf("TAT\n");        else         {            ll temp=0;            for(int i=0;i<len;i++)                temp=10ll*temp+s[i]-'0';            int time=0;            while(temp!=1&&time<=5)            {                temp=(ll)(sqrt(1.0*temp));                time++;            }            if(time<=5)printf("%d\n",time);            else printf("TAT\n");        }    }    return 0;}
0 0