A Math Problem题解

本文参考自: 原文地址

You are given a positive integer n, please count how many positive integers k satisfy  kknkk≤n
InputThere are no more than 50 test cases. 

Each case only contains a positivse integer n in a line. 

1n10181≤n≤1018 
OutputFor each test case, output an integer indicates the number of positive integers k satisfy  kknkk≤n in a line.Sample Input
1
4
Sample Output
1
2

题目大意:

输入一个n,输出一共有多少个k,满足pow(k,k)<=n;

(循环里的限制条件k<=n  不能用有,否则当n=1的时候就不能跳出循环了)

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long n;
	while(~scanf("%lld",&n))
	{
		
		for(int k=1;;k++)
		{
			long long m=n;
			for(int i=1;i<=k;++i)	m /=k;   
			if(m==0) 
			{
				cout<<k-1<<endl;	
				break;
			 } 
		} 
		 
	}
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/running987/article/details/81504418