数字很大,要用大数乘法。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
char s1[];
char s2[];
char* bignum(char *num1, char *num2)
{
if(strcmp(num1,"")==)
return "";
int length1 = strlen(num1);
int length2 = strlen(num2);
int i, l;
char *res = (char *)malloc(sizeof(char)*(length1 + length2)); //开辟相应内存
memset(res, , sizeof(char)*(length1 + length2));
for (i = length1 - ; i >= ; i--)
for (l = length2 - ; l >= ; l--)
{
res[i + l + ] += (num1[i] - '')*(num2[l] - '');
res[i + l] += res[i + l + ] / ; //马上进行进位
res[i + l + ] %= ;
}
int count = ;
while (res[count] == ) //由于保存的结果是从右向左的,所以要消除左部分的0;
{
count++;
}
char* ret = (char *)malloc(sizeof(char)*(length1 + length2 + ));
memset(ret, , sizeof(char)*(length1 + length2 + ));
for (l = , i = count; i < length1 + length2; l++, i++) //非0部分赋给ret
{
ret[l] = res[i] + '';
}
//printf("Ret=%s\n", ret);
return ret;
free(res);
free(ret);
} int main()
{
int t;
cin>>t;
while(t--)
{
int k;
cin>>k;
strcpy(s1,"");
strcpy(s2,"");
//printf("%s\n",s1);
while(k--)
{
//printf("%s\n",s1);
strcpy(s1,bignum(s1,s2));
for(int i=strlen(s1)-;i>=;i--)
{
if(s1[i] == '')
{
s1[i] = ;
continue;
}
else
{
s1[i] = s1[i] + ;
break;
}
}
}
printf("%s\n",s1);
}
return ;
}
05-11 01:40