static void Main(string[] args)
{
int maxLength = 10;
int n;
n = int.Parse(Console.ReadLine());
int[] num = new int[maxLength];
num[0] = 1;
int i, j;
int res = 0;
int plus = 0;
int flag = 1;
for (i = 2; i <= n; i++)
{
for (j = 1; j <= flag; j++)
{
if (flag > 0.9 * maxLength)
{
int[] b = new int[num.Length];
num.CopyTo(b, 0);
num = new int[maxLength * 2];
b.CopyTo(num, 0);
maxLength = maxLength * 2;
}
res = num[j - 1] * i + plus;
num[j - 1] = res % 10;
plus = res / 10;
}
while (plus > 0)
{
flag++;
num[flag - 1] = plus % 10;
plus = plus / 10;
}
}
string a;
a = num[flag - 1].ToString() +"."+ num[flag - 2].ToString() + num[flag - 3].ToString() + num[flag - 4].ToString() + "E"+ "+" + (flag - 1).ToString();
Console.WriteLine(a);
Console.ReadKey();
}
我写的这个算法计算大数时,计算时间非常长,请问可以如何优化一下呢?