一道快速幂和暴力的简单题,但用了pow一直wa,即使用自己写的pow也一直wa,后来觉得大概是自己用的pow的名字与内部的pow相同了,后来将自己写的pow改成了qpow,终于过了。
pow:精度问题。
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cmath>
using namespace std;
typedef long long ll;
ll qpow(ll a,int b){
ll ans=1,base=a;
while(b){
if(b%2==1)
ans=base*ans;
base=base*base;
b/=2;
}
return ans;
}
int main(){
ll n,k;
while(scanf("%lld",&n)!=EOF){
for(ll i=15;i>=1;i--){
if(qpow(i,i)<=n){
k=i;
break;
}
}
printf("%lld\n",k);
}
return 0;
}
#include<stdio.h>
#define LL long long
int main(void)
{
LL n, i, j, sum, now;
while(scanf("%lld", &n)!=EOF)
{
sum = 0;
for(i=1;i<=15;i++)
{
now = 1;
for(j=1;j<=i;j++)
now *= i;
if(now<=n)
sum++;
}
printf("%lld\n", sum);
}
return 0;
}