用不了那么麻烦。你仔细想一想吧,需要把a^b全部都求出来么?两个多位数相乘时,影响结果后4位的,不就是两个乘数的后4位么。#include #include #include int main (){int n;
scanf ("%d",&n);
while (n--)
{
long a,b,s;
scanf("%ld%ld",&a,&b);
s=1;while(b--){s=s*a%10000;}printf("%04ld\n",s);
...
#include using namespace std;int n;int fastpow(long long a, long long b){if(b==0) return 1;int temp = fastpow(a,b/2);if(b%2){return (temp*temp*a)%10000;...