public static TimeSpan Measure(long n)
        {
            // Measures the time used to factorize the number n using System.Diagnostics.Stopwatch
            // and returns it as a TimeSpan.

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Dictionary <long, long> res = factorizer.Run(n);

            stopwatch.Stop();

            // Check the result, we need to make sure our Factorization-implementation returns the correct result
            long v = 1;

            foreach (KeyValuePair <long, long> p in res)
            {
                v *= MathUtils.FastPowMod(p.Key, p.Value, long.MaxValue);
            }
            if (v != n)
            {
                throw new Exception("Wrong result: Factorization for " + n.ToString() + " multiplies to " + v.ToString() + ".");
            }

            // Return the TimeSpan
            return(stopwatch.Elapsed);
        }
Пример #2
0
        static void Main(string[] args)
        {
            long n = Convert.ToInt64(Console.ReadLine());

            Factorizer factorizer       = new Factorizer(new MillerRabin(40), new QuantumOrderFinder());
            Dictionary <long, long> res = factorizer.Run(n);

            foreach (KeyValuePair <long, long> kvp in res)
            {
                Console.WriteLine(kvp.Key.ToString() + ": " + kvp.Value.ToString());
            }
        }