题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5752
题目大意:
定义f(n)=⌊√n⌋,fy(n)=f(fy-1(n)),求y使得fy(n)=1。如果y>5输出TAT。(n<10100)
题目思路:
【模拟】
5层迭代是232,所以特判一下层数是5的,其余开根号做。注意数据有0。
队友写的。
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
char st[150];
int temp;
int ans;
while(scanf("%s",st)!=EOF)
{
if (st[0]=='0' || strlen(st)>10 || strlen(st)==10 && strcmp(st,"4294967295")>0)
printf("TAT\n");
else
if (strlen(st)==10 && strcmp(st,"2147483647")>0)
printf("5\n");
else
{
ans=0;
sscanf(st,"%d",&temp);
while(temp!=1)
{
temp=(int)(sqrt(double(temp)));
ans++;
}
if (ans==0) ans=1;
printf("%d\n",ans);
}
}
return 0;
}