2016 Multi-University Training Contest 3 Sqrt Bo

来源:互联网 发布:java自学书籍知乎 编辑:程序博客网 时间:2024/06/05 23:50

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
233233333333333333333333333333333333333333333333333333333333
 

Sample Output
3


代码:

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<algorithm>using namespace std;#define INF 0x3f3f3f3f#define N 110000__int64 f(__int64 x,__int64 tol){    __int64 y;    y=(__int64)sqrt(double(x));    if(y==1)        return tol+1;    else        return f(y,tol+1);}int main(){    __int64 i,n,sum,k;    char a[10000];    while(~scanf("%s",a)){        k=strlen(a);        if(k>10){            printf("TAT\n");continue;        }        n=0;        for(i=0;i<k;i++)            n=n*10+a[i]-'0';        sum=(__int64)sqrt(double(n));        if(sum==0)            printf("TAT\n");        else if(sum==1)            printf("1\n");        else        {            if(f(sum,1)>5)                printf("TAT\n");            else                printf("%I64d\n",f(sum,1));        }    }    return 0;}


0 0
原创粉丝点击