You are given a positive integer n, please count how many positive integers k satisfy
kk≤nkk≤n.
InputThere are no more than 50 test cases.
Each case only contains a positivse integer n in a line.
1≤n≤10181≤n≤1018
OutputFor each test case, output an integer indicates the number of positive integers k satisfy kk≤nkk≤n in a line.Sample Input
1 4Sample Output
1 2
方法一:先打表,再比较
#include<iostream>
using namespace std;
typedef long long LL;
int main(void)
{
LL a[17];
for(LL i=1;i<16;i++){
a[i]=1;
for(LL j=1;j<=i;j++){
a[i]*=i;
}
}
LL n;
while(~scanf("%lld",&n)){
int ans=0;
for(int i=1;i<16;i++){
if(n>=a[i])
ans++;
else
break;
}
cout<<ans<<endl;
}
return 0;
}
方法二:快速幂
#include<iostream>
using namespace std;
typedef long long LL;
LL powermod(LL a,LL n){
LL res=1;
while(n){
if(n&1){
res*=a;
}
a*=a;
n>>=1;
}
return res;
}
int main(){
LL n,a[16],ans;
for(LL i=1;i<=15;i++){
a[i]=powermod(i,i);
}
while(~scanf("%lld",&n)){
ans=0;
for(LL i=1;i<=15;i++){
if(a[i]<=n)
ans++;
else
break;
}
printf("%d\n",ans);}
return 0;}