1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include<cstdio> #include<cstring> using namespace std; typedef long long ll; const int MAX=36000; struct num{ char n[MAX]; int len; };
inline void mul(num &a,num &b,num &ans){ int i,j,jw; num c; memset(c.n,0,sizeof(c.n)); for(i=0;i<a.len;i++){ jw=0; for(j=0;j<b.len;j++){ c.n[i+j]=a.n[i]*b.n[j]+jw+c.n[i+j]; jw=c.n[i+j]/10; c.n[i+j]%=10; } c.n[i+j]=jw; }
c.len=a.len+b.len; while(c.n[c.len-1]==0&&c.len>1)c.len--; ans=c; }
inline void numcpy(num &a,long long x){ memset(a.n,0,sizeof(a.n)); if(x==0){ a.len=1; return; } a.len=0; while(x!=0){ a.n[a.len]=x%10; x/=10; a.len++; } }
inline void pnum(num &a){ for(int i=a.len-1;i>=0;i--) printf("%d",a.n[i]); printf("\n"); }
num Fast_Power(ll a, ll b){ num ans, base; numcpy(ans,1); numcpy(base,a); while(b != 0){ if(b & 1)mul(ans,base,ans); mul(base,base,base); b >>= 1; } return ans; }
int main(){ int a,b; scanf("%d%d",&a,&b); num t=Fast_Power(a,b); pnum(t); return 0; }
|