HDU 5752 Sqrt Bo (数论)

Sqrt Bo

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5752

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


题意:


给出一个数(1e100),问能否在开5次平方以内收敛到1.
若能则输出次数,否则输出TAT.


题解:


首先找一个边界:恰好开5次平方不能到1的.很容易找出是2^32.
由于输入数据很大,所以要用字符串读入,长度大于10的串直接输出TAT.
长度合适的串用sscanf读出数据,先与2^32比较,再进行开平方操作.
要注意0的情况:0输出TAT.


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 700
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;

char str[120];

int main(int argc, char const *argv[])
{
    //IN;

    while(scanf("%s", str) != EOF)
    {
        int len = strlen(str);
        if(len > 10) {
            printf("TAT\n");
            continue;
        }

        LL n = 0;
        sscanf(str,"%I64d", &n);

        LL cmps = 1LL<<32;
        if(n >= cmps || !n) {
            printf("TAT\n");
            continue;
        }

        int cnt = 0;
        while(n != 1){
            n = sqrt(n);
            cnt++;
        }

        printf("%d\n", cnt);
    }

    return 0;
}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5709459.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值