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\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;
}
HDU 5752 Sqrt Bo (数论)的更多相关文章
- HDU 5752 Sqrt Bo【枚举,大水题】
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- hdu 5752 Sqrt Bo 水题
Sqrt Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 Description Let's define the function f ...
- hdu 5752 Sqrt Bo
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- 【模拟】HDU 5752 Sqrt Bo
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 题目大意: 定义f(n)=⌊√n⌋,fy(n)=f(fy-1(n)),求y使得fy(n)=1. ...
- HDU 5752 Sqrt Bo (思维题) 2016杭电多校联合第三场
题目:传送门. 题意:一个很大的数n,最多开5次根号,问开几次根号可以得到1,如果5次还不能得到1就输出TAT. 题解:打表题,x1=1,x2=(x1+1)*(x1+1)-1,以此类推.x5是不超过l ...
- 七夕节 (HDU - 1215) 【简单数论】【找因数】
七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...
- HDU 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...
- HDU 5752
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
随机推荐
- hive学习笔记——表的基本的操作
1.hive的数据加载方式 1.1.load data 这中方式一般用于初始化的时候 load data [local] inpath '...' [overwrite] into table t1 ...
- UserAccountInfo时间倒计时
界面如下: 代码如下: using System;using System.Collections.Generic;using System.ComponentModel;using System.D ...
- $.toJSON的用法或把数组转换成json类型
1. html页面全部代码 <html> <head> <title></title> <script src="../../S ...
- apache开源项目--Syncope
Apache Syncope is an Open Source system for managing digital identities in enterprise environments, ...
- Python用smtplib发送邮件
参照了下面: 1. 先随便照着试试这个: http://blog.csdn.net/zhaoweikid/article/details/1638349 2. 这个写了一个很简洁的代码,看过NO.1就 ...
- 【转】NSDictionary以及NSMutableDictionary的用法
原文网址:http://my.oschina.net/u/1245365/blog/177736 摘要 Foundation中的字典是由 键—值 对组成的数据集合.通过key(键),查找对应的valu ...
- 【转】./a.out 2>&1 > outfile
原文网址:http://www.cnblogs.com/zhaoyl/archive/2012/10/22/2733418.html APUE 3.5关于重定向有个容易迷惑人的问题: ./a.out ...
- 不重启mysql情况修改参数变量
地球人都知道,更新mysql配置my.cnf需要重启mysql才能生效,但是有些时候mysql在线上,不一定允许你重启,这时候应该怎么办呢? 看一个例子: 1 2 3 4 5 6 7 8 9 10 m ...
- 【转】traits技术及模板偏特化
#include <iostream> using namespace std; struct __xtrue_type { }; // define two mark-type stru ...
- Nginx源码安装及调优配置
导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优 ...