南邮 OJ 1439 xx

xx

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 122            测试通过 : 30 

比赛描述

使得x^x达到或超过n位数字的最小正整数x是多少?




输入

输入一个正整数n  n<=2 000 000 000


输出

输出使得x^x达到n位数字的最小正整数x


样例输入

11

样例输出

10

题目来源

NUPT ACM 2010 Personal Ranking Contest




/* AC 6MS
#include<iostream>
#include<cmath>
#define N 250000000				// N*log10(N)=2099485002.1680094023931305526378

int main(){
	int n,l,r,mid;
	scanf("%d",&n);
	l = 0;
	r = N;
	while(1){
		mid = (l+r)>>1;
		if(n<=(int)((mid-1)*log10((float)(mid-1)))+1){
			r = mid-1;
		}else if((int)(mid*log10((float)mid))+1<n){
			l = mid+1;
		}else{
			break;
		}
	}
	printf("%d\n",mid);
}
*/

/* 1MS 不过VS中会显示错误
#include<iostream>
#include<cmath>
#define N 250000000
int main(){
	int n,l,r,mid;
	scanf("%d",&n);
	l = 0;
	r = N;
	while(1){
		mid = (l+r)>>1;
		if(n<=(int)((mid-1)*log10((mid-1)))+1){
			r = mid-1;
		}else if((int)(mid*log10(mid))+1<n){
			l = mid+1;
		}else{
			break;
		}
	}
	printf("%d\n",mid);
}
*/
#include<iostream>
#include<cmath>
#define N 250000000				// N*log10(N)=2099485002.1680094023931305526378

int main(){
	int n,l,r,mid;
	scanf("%d",&n);
	l = 0;
	r = N;
	while(1){
		mid = (l+r)>>1;
		if(n<=(int)((mid-1)*log10((float)(mid-1)))+1){
			r = mid-1;
		}else if((int)(mid*log10((float)mid))+1<n){
			l = mid+1;
		}else{
			break;
		}
	}
	printf("%d\n",mid);
}





你可能感兴趣的:(ACM,xx,南邮OJ)