Sqrt Bo
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 82 Accepted Submission(s): 42
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
Source
2016 Multi-University Training Contest 3
题目大意:
给你一个很大很大的数,判断它的根号多少次等于1,如果超过5次,输出TAT。
思路:
1、首先,我们知道如果一个数超过了Long Long,那么其根号次数一定超过五次。
2、那么输入的字符串长度大于18的时候,是一定输出TAT的、那么如果字符串长度小于18的时候,暴力根号一下,如果次数大于5仍然输出TAT,如果次数小于5,输出次数。
3、注意,0是输出TAT的、
Ac代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
#define ll long long int
char a[1000000];
int main()
{
while(~scanf("%s",a))
{
int n=strlen(a);
if(n>18)
{
printf("TAT\n");
}
else
{
ll tmp=0;
for(int i=0;i<n;i++)
{
tmp=tmp*10+a[i]-'0';
}
int ans=-1;
for(int j=1;j<=5;j++)
{
tmp=sqrt(tmp);
if(tmp==1)
{
ans=j;break;
}
}
if(ans==-1)
{
printf("TAT\n");
}
else printf("%d\n",ans);
}
}
}