标签:
题目大意:给了一个2^E的前缀n,已知前缀n的位数不到2^E的位数的一半,找出满足条件的最小E。
题目解析:设2^E为i位数,则有n*10^i<2^E<(n+1)*10^i。解不等式得到i*log10(n)/log10(2)<E<i*log10(n+1)/log10(2)。从log10(n)+2开始枚举 i 即可。
代码如下:
# include<iostream> # include<cstdio> # include<cmath> # include<cstring> # include<algorithm> using namespace std; void work(unsigned n) { double u=(double)n; int i=log10(u)+2; while(1){ int low=floor(log2(u)+i*log2(10)); int high=ceil(log2(u+1)+i*log2(10)); if(high>low+1){ printf("%d\n",low+1); return ; } ++i; } } int main() { unsigned n; while(scanf("%u",&n)!=EOF) { work(n); } return 0; }
UVA-701 The Archeologists' Dilemma (数论)
标签:
原文地址:http://www.cnblogs.com/20143605--pcx/p/4715041.html