Ejemplo n.º 1
0
        public static void IIB()
        {
            Console.WriteLine("II.");
            Console.WriteLine("Finds the first five prime numbers with 100 binary digits");
            int countPrimeNumberFound = 0;
            int tryNumber             = 0;

            while (countPrimeNumberFound < 5)
            {
                List <int> positionsOf1s = new List <int> // Trusting that the number will have 100 binary digits.
                {
                    GlobalVariables.MAX_NUM - 100,
                    GlobalVariables.MAX_NUM - 1
                };
                int k = 20;

                BigNum primeNumberSuspect = new BigNum();
                primeNumberSuspect.ReadNum(positionsOf1s);
                Console.WriteLine($"try number: {++tryNumber}");
                if (MathOps.IsPrime(primeNumberSuspect, k))
                {
                    Console.WriteLine($"Prime {countPrimeNumberFound}: {primeNumberSuspect.BinaryValue}");
                    Console.WriteLine();
                }

                primeNumberSuspect.AddNum(GlobalVariables.two);
            }

            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public static void N()
        {
            Console.WriteLine("(N) Using IsPrime method.");
            Console.WriteLine("Checking if 7, 513, 9973, 2147483647. We should get: true, false, true, true.");
            BigNum n1 = new BigNum(7);
            BigNum n2 = new BigNum(513);
            BigNum n3 = new BigNum(9973);
            BigNum eightMarsenNumber = new BigNum(2147483647);
            int    k = 20;

            Console.WriteLine(MathOps.IsPrime(n1, k).ToString());
            Console.WriteLine(MathOps.IsPrime(n2, k).ToString());
            Console.WriteLine(MathOps.IsPrime(n3, k).ToString());
            Console.WriteLine(MathOps.IsPrime(eightMarsenNumber, k).ToString());

            Console.WriteLine();
        }