hdu5752Sqrt Bo+水题

来源:互联网 发布:js获取当前鼠标的位置 编辑:程序博客网 时间:2024/05/17 23:33

Problem Description
Let’s define the function f(n)=⌊n−−√⌋.

Bo wanted to know the minimum number y which satisfies fy(n)=1.

note:f1(n)=f(n),fy(n)=f(fy−1(n))

It is a pity that Bo can only use 1 unit of time to calculate this function each time.

And Bo is impatient, he cannot stand waiting for longer than 5 units of time.

So Bo wants to know if he can solve this problem in 5 units of time.

Input
This problem has multi test cases(no more than 120).

Each test case contains a non-negative integer n(n<10100).

Output
For each test case print a integer - the answer y or a string “TAT” - Bo can’t solve this problem.

Sample Input

233
233333333333333333333333333333333333333333333333333333333

Sample Output

3
TAT

题意:给一个数。问能不能5次内计算f(n)=n.使得f(n)=1;
直接观察就可以发现跟2的几次幂有关。sqrt3=1,sqrt4=2,sqrt241=3也就是说在sqrt2321=5,再大就不可以了。所以直接判断字符串长度是否为10位以内(232)。是的话直接转化成一个long long存下来,计算次数。注意的是0应该不可以,1是0次。

#include<cstdio>#include<cstring>#include<cmath>using namespace std;#define LL long longchar a[122];int main(){    while(scanf("%s",a)!=EOF){        int len=strlen(a);        if(len>=11) printf("TAT\n");        else{            LL sum=0;            for(int i=0;i<len;i++) sum=sum*10+a[i]-'0';            if(sum==0){                printf("TAT\n");                continue;            }            int cnt=0;            //printf("%I64d\n",sum);            while(sum>1){                sum=(int)(sqrt(sum)+0.0000001);                cnt++;                //printf("%I64d\n",sum);            }            if(cnt>5) printf("TAT\n");            else printf("%d\n",cnt);        }    }    return 0;}
0 0