HDU 5752 Sqrt Bo

可以先尝试一下longlong范围内哪个数已经不可能在5步之内得到1. 剩下的模拟算一下即可。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi = acos(-1.0), eps = 1e-8;
void File()
{
    freopen("D:\in.txt", "r", stdin);
    freopen("D:\out.txt", "w", stdout);
}
inline int read()
{
    char c = getchar();  while (!isdigit(c)) c = getchar();
    int x = 0;
    while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
    return x;
}

char s[10000];
LL f(LL a) { return (LL) sqrt(a); }

int main()
{
    while(~scanf("%s",s))
    {
        if(strlen(s)>=11) { printf("TAT
"); continue; }
        int g=0; LL x=0; for(int i=0;s[i];i++) x=x*10+s[i]-'0';
        for(int i=1;i<=5;i++) { x=f(x); if(x==1) {printf("%d
",i); g=1;break;} }
        if(g==0) printf("TAT
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/5710123.html