【模拟】HDU 5752 Sqrt Bo

本文提供了一道 HDU 5752 的算法题解,题目要求通过模拟运算来求解一个特定数学问题。利用 C 语言实现了一个简洁高效的程序来解决该问题,并对特殊情况进行了特判。

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

题目链接:

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值