HDU-5752 Sqrt Bo(处理字符串)

来源:互联网 发布:orancle in优化 编辑:程序博客网 时间:2024/06/08 07:33

Sqrt Bo

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1346    Accepted Submission(s): 600


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(fy1(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
233233333333333333333333333333333333333333333333333333333333
 

Sample Output
3TAT
 
题意:给你个数,问能否在五次之内开方向下取整取到1,取得到输出,反之tat
由2五次平方得到2^32次方,即10的9次方,int不会爆

太大了,先用字符串存储,符合再转化成数字

/**/#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;//typedef long long ll;int main(){   char str[105];   while(~scanf("%s",str))   {       int len = strlen(str);       if(len >10 || strcmp(str,"0") == 0)//如果太长或者是0            printf("TAT\n");        else        {            long long ans = 0;            for(int i = 0;i < len;i++)            {                ans = ans*10 + str[i] - '0';            }            int sum = 0;            while(ans > 1)            {                sum++;                ans = floor(sqrt(ans));            }            if(sum <= 5)                printf("%d\n",sum);            else                printf("TAT\n");        }   }   return 0;}


0 0
原创粉丝点击