HDU5752 Sqrt Bo

来源:互联网 发布:web前端和java哪个难 编辑:程序博客网 时间:2024/05/18 03:23

题目链接:HDU5752

Sqrt Bo

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


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,多于5次输出TAT。
题目分析:显然2^2,2^4,2^8,2^16,2^32是分界点,对可能在2^32以内的数判断下属于那个区间即可,注意对0的特判,0时输出TAT。
////  main.cpp//  Sqrt Bo////  Created by teddywang on 2016/7/27.//  Copyright © 2016年 teddywang. All rights reserved.//#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){    long long int ans[10];    ans[1]=1;ans[2]=4;    ans[3]=16;ans[4]=256;    ans[5]=256*256;ans[6]=ans[5]*ans[5];    char s[2000];    while(~scanf("%s",s))    {        if(strcmp(s,"0")==0) printf("TAT\n");        else{            int flag=1;            if(strlen(s)<=10)            {                long long buf=0;                for(int i=0;i<strlen(s);i++)                {                    buf=10*buf+s[i]-'0';                }                for(int j=1;j<6;j++)                {                    if(buf>=ans[j]&&buf<ans[j+1])                    {                        cout<<j<<endl;                        flag=0;                        break;                    }                }            }            if(flag==1) printf("TAT\n");        }    }}



0 0