洛谷P2759 奇怪的函数
生活随笔
收集整理的這篇文章主要介紹了
洛谷P2759 奇怪的函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
P2759 奇怪的函數
題目描述
使得 x^x 達到或超過 n 位數字的最小正整數 x 是多少?
輸入輸出格式
輸入格式:?
一個正整數 n
?
輸出格式:?
使得 x^x 達到 n 位數字的最小正整數 x
?
輸入輸出樣例
輸入樣例#1:11 輸出樣例#1:
10
說明
n<=2000000000
換底公式
?
/*相當于解不等式x^x>=10^(n-1)兩邊取常用對數x*log10(x)>=n-1左邊是單調增的然后二分查找就行了 */ #include<iostream> #include<cstdio> #include<cmath> using namespace std; int n,ans; bool check(int x){if(x*(log(x)/log(10))>=n-1)return 1;return 0; } int main(){scanf("%d",&n);int l=0,r=2000000000;while(l<=r){int mid=(l+r)>>1;if(check(mid))r=mid-1,ans=mid;else l=mid+1;}printf("%d",ans); }?
轉載于:https://www.cnblogs.com/thmyl/p/7429244.html
總結
以上是生活随笔為你收集整理的洛谷P2759 奇怪的函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 作业要求 20171130 每周例行报告
- 下一篇: 运用OpenMP提速图像处理速度