目录
题目描述
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
You are given a positive integer n, please count how many positive integers k satisfy kk≤n.
Input
There are no more than 50 test cases.
Each case only contains a positivse integer n in a line.
1≤n≤10^18
Output
For each test case, output an integer indicates the number of positive integers k satisfy kk≤n in a line.
Sample Input
1 4
Sample Output
1 2
题意分析
题意:求【1,N】之间有多少满足 k^k <= N 的数量
快速幂+暴力能过。但要注意限定条件。
AC代码
#include <iostream>
#include <cmath>
using namespace std;
long long quick(long long a,long long b)
{
long long ans=1;
while(b!=0)
{
if(b&1) ans=(ans*a);
b>>=1;
a = (a*a);
}
return ans;
}
int main()
{
long long n,i,sum;
while(cin>>n)
{
sum=0;
for(i=1;i<=15;i++) //限制条件没有,直接WA
{
if(quick(i,i)<=n)
{
sum++;
}
else break;
}
cout<<sum<<endl;
}
return 0;
}