新手写的高精度承高精度,求大佬优化
作者:
HLQS
,
2024-11-27 16:58:13
,
所有人可见
,
阅读 2
#include <stdio.h>
#include <string.h>
#define N 100000
#define N1 10000000
int len1, len2;
void mul(int a[], int b[])
{
int c[N1] = {0};
int th1, t = 0;
int i, j, k;
for (i = 0; i < len2; i++)
{
for (j = i, k = 0, t = 0; k < len1; j++, k++)
{
th1 = a[k] * b[i];
c[j] = c[j] + th1 + t;
t = c[j] / 10;
c[j] %= 10;
}
if (t)
{
c[j] = t;
t = 0;
}
}
while (c[j] == 0 && j > 0)
j--;
for (i = j; i >= 0; i--)
printf("%d", c[i]);
}
int main()
{
char str1[N], str2[N];
int num1[N] = {0}, num2[N] = {0};
int i, j;
scanf("%s", str1);
scanf("%s", str2);
len1 = strlen(str1), len2 = strlen(str2);
for (i = 0, j = len1 - 1; i < len1; i++, j--)
num1[i] = str1[j] - '0';
for (i = 0, j = len2 - 1; i < len2; i++, j--)
num2[i] = str2[j] - '0';
mul(num1, num2);
return 0;
}
优化?FFT 我不会。