using System;
public class Test
{
public static void Main()
{
Factorial(1000);
}
public static void Factorial(int n)
{
var number = new int[999999];
number[0] = 1;
int numLength = 1;
for (int times = 2; times <= n; times++)
numLength = Multiply(times, number,numLength);
for (int i = numLength - 1; i >= 0; i--)
Console.Write(number[i]);
}
static int Multiply(int times, int[] number,int numLength)
{
int carry = 0;
for (int i = 0; i < numLength; i++)
{
int product = number[i] * times + carry;
number[i] = product % 10;
carry = product / 10;
}
while (carry != 0)
{
number[numLength] = carry % 10;
carry /= 10;
numLength++;
}
return numLength;
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCUZhY3RvcmlhbCgxMDAwKTsKCX0KICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBGYWN0b3JpYWwoaW50IG4pCiAgICB7CiAgICAgICAgdmFyIG51bWJlciA9IG5ldyBpbnRbOTk5OTk5XTsKICAgICAgICBudW1iZXJbMF0gPSAxOwogICAgICAgIGludCBudW1MZW5ndGggPSAxOwogICAgICAgIGZvciAoaW50IHRpbWVzID0gMjsgdGltZXMgPD0gbjsgdGltZXMrKykKICAgICAgICAgICAgbnVtTGVuZ3RoID0gTXVsdGlwbHkodGltZXMsIG51bWJlcixudW1MZW5ndGgpOwoKICAgICAgICBmb3IgKGludCBpID0gbnVtTGVuZ3RoIC0gMTsgaSA+PSAwOyBpLS0pCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGUobnVtYmVyW2ldKTsKICAgIH0KCiAgICAKICAgIHN0YXRpYyBpbnQgTXVsdGlwbHkoaW50IHRpbWVzLCBpbnRbXSBudW1iZXIsaW50IG51bUxlbmd0aCkKICAgIHsKICAgICAgICBpbnQgY2FycnkgPSAwOyAKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG51bUxlbmd0aDsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaW50IHByb2R1Y3QgPSBudW1iZXJbaV0gKiB0aW1lcyArIGNhcnJ5OwogICAgICAgICAgICBudW1iZXJbaV0gPSBwcm9kdWN0ICUgMTA7CiAgICAgICAgICAgIGNhcnJ5ID0gcHJvZHVjdCAvIDEwOwogICAgICAgIH0KCiAgICAgICAgd2hpbGUgKGNhcnJ5ICE9IDApCiAgICAgICAgewogICAgICAgICAgICBudW1iZXJbbnVtTGVuZ3RoXSA9IGNhcnJ5ICUgMTA7CiAgICAgICAgICAgIGNhcnJ5IC89IDEwOwogICAgICAgICAgICBudW1MZW5ndGgrKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG51bUxlbmd0aDsKICAgIH0KfQ==