POWER - Lũy thừa
Tác giả: hieult
Ngôn ngữ: C++
#include <stdio.h>
#include <math.h>
main()
{
int n,c[10000],x2,y2,v;
double a[10000],b[10000],x,y;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lf",&a[i]);
scanf("%lf",&b[i]);
}
for(int i=0;i<n;i++)
{
x=a[i];
y=b[i];
x2=0;
y2=0;
while(x>=1)
{
x=x/2;
x2++;
}
while(y>=1)
{
y=y/2;
y2++;
}
if(y2>x2)
c[i]=y2-1;
else
{
for(int j=y2-1;j>0;j--)
{
v=int(pow(b[i]+0.1,1./j));
if(a[i]<=pow(v,j)&&pow(v,j)<=b[i])
{
c[i]=j;
break;
}
}
}
}
for(int i=0;i<n;i++)
printf("Case #%d: %d\n",i+1,c[i]);
}