Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Benchmark
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- for(int i = 0; i < 10; i++) {
- Fact();
- }
- }
- public static void Fact() {
- var watch = System.Diagnostics.Stopwatch.StartNew();
- var result = new long[1000_000];
- result[0] = 1;
- var length = 1;
- for(long i = 1; i <= 1000_00L; i++)
- {
- long w = 0;
- for(int j = 0; j < length; j++)
- {
- var rn = result[j] * i + w;
- w = rn / 1000_000_000L;
- result[j] = rn % 1000_000_000L;
- }
- if(w != 0)
- {
- length += 1;
- result[length - 1] = w;
- }
- }
- watch.Stop();
- System.Console.WriteLine("{0}! has {1} digits, time taken: {2}ms", 100_000L, 9 * (length - 1) + result[length - 1].ToString().Length,
- watch.ElapsedMilliseconds);
- }
- }
- }
Add Comment
Please, Sign In to add comment