整数性质和精度测试

本文提供了一种通过二分查找解决数学问题的方法,即求解X^X达到特定位数n时的最小x值。通过引入对数运算和位数计算公式,实现高效求解过程。

  【题目】:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=612

  【题意】:

求X^X(X的X次方)达到n位时最小x的值。
【分析】:首先我们可以知道位数和X的大小成正相关。
我们不可能枚举这个x,那么就要二分。
然后怎么知道x^2有多少位呢?
k=(x+0.0)*log10(x)+1 其实就是10的位数

输入】:多组测试数据,每组数据占一行包含一个整数n,1<=n<=100000000.
代码】:
 1 /*http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=612
 2 关键是对数处理位数
 3 */
 4 #include <iostream>
 5 #include <stdio.h>
 6 #include <math.h>
 7 #include <vector>
 8 #define eps 1e-15
 9 #define LL long long
10 #define INF 1e9
11 using namespace std;
12 
13 LL F(LL x){
14     if (x==1) return 1;
15     double k=(x+0.0)*log10(x);
16     return (LL)k+1;
17 }
18 LL n;
19 int main(){
20 //    freopen("out.txt","w",stdout);
21     while(cin>>n){
23         LL l=0,r=INF,times=0;
24         while(l<r && times<70){
25             times++;
26             LL m=l+(r-l)/2;
27             if (F(m)>=n) r=m;else l=m+1;
28         }
29         cout<<l<<endl;
30     }
31     return 0;
32 }
 
 

 


转载于:https://www.cnblogs.com/little-w/p/3698987.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值