daily pastebin goal
74%
SHARE
TWEET

Untitled

a guest Oct 18th, 2018 69 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. namespace Benchmark
  2. {
  3.     public class Program
  4.     {
  5.         public static void Main(string[] args)
  6.         {
  7.             for(int i = 0; i < 10; i++) {
  8.                 Fact();
  9.             }
  10.         }
  11.  
  12.         public static void Fact() {
  13.             var watch = System.Diagnostics.Stopwatch.StartNew();
  14.  
  15.             var result = new long[1000_000];
  16.             result[0] = 1;
  17.             var length = 1;
  18.             for(long i = 1; i <= 1000_00L; i++)
  19.             {
  20.                 long w = 0;
  21.                 for(int j = 0; j < length; j++)
  22.                 {
  23.                     var rn = result[j] * i + w;
  24.                     w = rn / 1000_000_000L;
  25.                     result[j] = rn % 1000_000_000L;
  26.                 }
  27.                 if(w != 0)
  28.                 {
  29.                     length += 1;
  30.                     result[length - 1] = w;
  31.                 }
  32.             }
  33.            
  34.             watch.Stop();
  35.             System.Console.WriteLine("{0}! has {1} digits, time taken: {2}ms", 100_000L, 9 * (length - 1) + result[length - 1].ToString().Length,
  36.                 watch.ElapsedMilliseconds);
  37.         }
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top