如前面我碰到的一样,使用的是CX大牛提供的大数模板,呵呵。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int OneNode = 1000000 ;
const int NodeLen = 6 ;
const int NumMax = 15 ;
struct BigNum
  {
unsigned num[NumMax] ;
unsigned numlen ;
 void set(unsigned sm=0) { num[0] = sm ; numlen = 1; }
void set(char *string , int strlen)
 {
numlen = (strlen-1) / NodeLen + 1 ;
memset (num , 0 , sizeof(unsigned)*numlen );
int temp , i ;
for( i=strlen-1 ; i>=0 ; i-- )
 {
temp = i / NodeLen ;
num[temp] = num[temp]*10 + string[strlen-1-i]-'0' ;
}
}
void print()
 {
printf("%d",num[numlen-1]);
int i = numlen-1;
while( i )
 {
i--;
printf("%06d",num[i]);
}
printf("\n");
}
};

void Mul(BigNum &a,BigNum &b,BigNum &c)
  {
unsigned carry = 0 , lenmax = a.numlen+b.numlen-1 ,i,j ;
unsigned __int64 temp ;
c.numlen = lenmax;
for ( i=0 ; i<lenmax ; i++ )
 {
temp = carry ;
for ( j=0 ; j<a.numlen ; j++ )
 {
if ( i<j )
break;
if ( i-j >= b.numlen )
 {
j = i-b.numlen ;
continue;
}
temp += (unsigned __int64)a.num[j] * b.num[i-j] ;
}
carry = temp / OneNode ;
c.num[i] = temp % OneNode ;
}
if(carry)
 {
c.num[i] = carry ;
c.numlen ++;
}
}

void Cpy(BigNum &a , BigNum &b)
  {
a.numlen=b.numlen;
memcpy(a.num,b.num,sizeof(unsigned)*b.numlen);
}

BigNum a,b,c;

int main()
  {
int n,d,i,j,temp;
char str[2],ch;
while(1)
 {
scanf("%d%d",&n,&d);
if(n==0&&d==0)break;
i=0;temp=n;
 while(temp!=0) {str[i++]=temp%10+48;temp/=10;}
for(j=0;j<i-j-1;j++)
 {
ch=str[j];
str[j]=str[i-j-1];
str[i-j-1]=ch;
}
a.set(str,i);

c.set("1",1);
for(i=0;i<d;i++)
 {
Cpy(b,c);
Mul(a,b,c);
}
c.print();

}
return 0;
}

|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
29 | 30 | 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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论

阅读排行榜
评论排行榜
|
|