Sqrt Bo

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


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
233 233333333333333333333333333333333333333333333333333333333
 

 

Sample Output
3 TAT
 
 
 
题意:给出一个字符串,若开五次根号能开到1,则输出开方次数,否则输出“TAT”。
 
打了一下午比赛做了一道这么个签到题。。。%>_<%
 
 
 
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
using namespace std;
#define maxn 1120
char str[maxn];

int main()
{
    while(scanf("%s", str)!=EOF)
    {
        int ans = 0;
        long long n = 0;

        for(int i=0; str[i] && i<11; i++)
            n = n*10+str[i]-'0';

        while(n != 1)
        {
            n = sqrt(n);
            ans ++;
            
            if(ans>6)
                break;
        }

        if(ans <= 5) printf("%d\n", ans);

        else   printf("TAT\n");

    }

    return 0;
}
View Code

 

 

posted on 2016-07-26 17:12  不忧尘世不忧心  阅读(183)  评论(0编辑  收藏  举报