2016 Multi-University Training Contest 3 hdu 5752 Sqrt Bo【思维】

本文解析了一道关于计算根号序列最小次数直至结果为1的编程题。介绍了题目的背景及要求,并提供了AC代码实现,包括输入大整数处理、特殊情况判断等细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
        }
    }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值