#include<stdio.h>
#include<string.h>
#define esp 1e20
int fun1(int n,int k)
{
double res=1.0;
double base=n*1.0;
while(k)
{
if(k&1)
{
res*=base;
while(res>=esp) res/=10;
}
base*=base;
while(base>=esp) base/=10;
k>>=1;
}
while(res>=1000) res/=10;
return (int) res;
}
int main()
{
int ncase,k,n;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%d%d",&n,&k);
printf("%d\n",fun1(n,k));
}
return 0;
}
另一种方法:
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
__int64 x,res;
double n,k,y;
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%lf%lf",&n,&k);
n=k*log10(n);
x=(__int64)(n);
y=n-x;
res=(__int64)(pow(10,y)*100);
printf("%I64d\n",res);
}
return 0;
}
本文提供了两种处理大数幂运算的有效方法。第一种方法使用循环移位和位操作来减少乘法次数并避免溢出;第二种方法利用对数特性,通过查找指数的小数部分并计算10的该次幂来获得结果的精确值。
401

被折叠的 条评论
为什么被折叠?



