zoukankan      html  css  js  c++  java
  • 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.
    ##代码: ``` cpp #include #include #include #include #include #include #include #include #include #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
    ");
            continue;
        }
    
        LL n = 0;
        sscanf(str,"%I64d", &n);
    
        LL cmps = 1LL<<32;
        if(n >= cmps || !n) {
            printf("TAT
    ");
            continue;
        }
    
        int cnt = 0;
        while(n != 1){
            n = sqrt(n);
            cnt++;
        }
    
        printf("%d
    ", cnt);
    }
    
    return 0;
    

    }

  • 相关阅读:
    【webpack4x】基本概念
    React平时的一些踩坑总结
    redux-saga学习进阶篇二
    redux-saga学习进阶篇一
    redux-saga学习基础篇一
    性能优化之节流(throttling)与防抖(debounce)
    git操作之发现push到远程仓库的代码有误
    git高级浅入之当我们需要去恢复到某个版本
    git高级浅入之当我们需要修改某次commit信息
    http验证CertificateValidation
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5709459.html
Copyright © 2011-2022 走看看