Beispiel #1
0
        private void btnEnumeratePrimeFactors_Click(object sender, EventArgs e)
        {
            DateTime startTime = DateTime.UtcNow;
            Coprimes factorsFinder = new Coprimes(CoprimeTo, CoprimeMin, CoprimeMax);
            List<BigInteger> factors = factorsFinder.GetPrimeFactors().ToList();
            string joinedFactors = string.Join(Environment.NewLine, factors);
            TimeSpan factorsTimeElapsed = DateTime.UtcNow.Subtract(startTime);

            factorsTimeElapsed.ToString("m'm 's's.'FFFFFFF");

            StringBuilder resultString = new StringBuilder();
            resultString.AppendFormat("Total # of prime found in range: {0}", factors.Count);
            resultString.AppendLine();
            resultString.AppendFormat("Total time elapsed: {0}", factorsTimeElapsed.ToString("m'm 's's.'ffff"));
            resultString.AppendLine();
            resultString.Append(joinedFactors);

            tbOutput.Clear();
            DisplayOutput(resultString.ToString());
            tbOutput.Select(0, 0);
            tbOutput.ScrollToCaret();
        }
Beispiel #2
0
        public void TestFindPrimeFactors32bit()
        {
            BigInteger coprimeTo = 1202664026348236889;
            BigInteger coprimeMin = 1069760585;
            BigInteger coprimeMax = 1202664026348236890;
            int expectedCoprimeCount = 2;
            BigInteger primeP = 1074936217;
            BigInteger primeQ = 1118823617;

            Coprimes coprimes = new Coprimes(coprimeTo, coprimeMin, coprimeMax);
            List<BigInteger> resultCoprimes = coprimes.GetPrimeFactors().ToList();
            int resultCoprimeCount = resultCoprimes.Count;

            Assert.AreEqual(expectedCoprimeCount, resultCoprimeCount);
            Assert.AreEqual(resultCoprimes[0], primeP);
            Assert.AreEqual(resultCoprimes[1], primeQ);
        }
Beispiel #3
0
        public void TestFindPrimeFactors64bit()
        {
            BigInteger coprimeTo = BigInteger.Parse("90459209396766660489526818707270239963");
            BigInteger coprimeMin = 9223506588021000000;
            BigInteger coprimeMax = BigInteger.Parse("90459209396766660489526818707270239964");
            int expectedCoprimeCount = 2;
            BigInteger primeP = 9223506588022268141;
            BigInteger primeQ = 9807464062988563943;

            Coprimes coprimes = new Coprimes(coprimeTo, coprimeMin, coprimeMax);
            List<BigInteger> resultCoprimes = coprimes.GetPrimeFactors().ToList();
            int resultCoprimeCount = resultCoprimes.Count;

            Assert.AreEqual(expectedCoprimeCount, resultCoprimeCount);
            Assert.AreEqual(resultCoprimes[0], primeP);
            Assert.AreEqual(resultCoprimes[1], primeQ);
        }
Beispiel #4
0
        public void TestFindPrimeFactors()
        {
            BigInteger coprimeTo = 111247819;
            BigInteger coprimeMin = 2;
            BigInteger coprimeMax = 111247820;
            int expectedCoprimeCount = 2;
            BigInteger primeP = 10007;
            BigInteger primeQ = 11117;

            Coprimes coprimes = new Coprimes(coprimeTo, coprimeMin, coprimeMax);
            List<BigInteger> resultCoprimes = coprimes.GetPrimeFactors().ToList();
            int resultCoprimeCount = resultCoprimes.Count;

            Assert.AreEqual(expectedCoprimeCount, resultCoprimeCount);
            Assert.AreEqual(resultCoprimes[0], primeP);
            Assert.AreEqual(resultCoprimes[1], primeQ);
        }