Example #1
0
        public void FindClosePrimes()
        {
            var L = 10000000ul;

            var primes = new List <ulong>();

            var count = 0;

            for (var i = 1ul; i < L; i++)
            {
                var ii = i * i;
                primes.Clear();
                for (var j = ii + 1; j <= ii + 40; j++)
                {
                    if (MillerRabinPrimality.IsPrime(j))
                    {
                        primes.Add(j);
                    }
                }
                if (primes.Count >= 6)
                {
                    Console.WriteLine(new { i, ii });
                    Console.WriteLine(primes.Join());
                    Console.WriteLine();
                    count++;
                }

                if (count >= 100)
                {
                    break;
                }
            }
        }
Example #2
0
        static bool Check(ulong ii, ulong[] additionals, bool[] isPrimes)
        {
            var first = additionals[0];
            var last  = additionals[additionals.Length - 1];

            for (var rem = first; rem <= last; rem++)
            {
                var mr = MillerRabinPrimality.IsPrime(ii + rem);
                if (mr != isPrimes[rem])
                {
                    return(false);
                }
            }
            return(true);
        }
Example #3
0
        public void CanCalcPrimalityCorrectlyForUlong()
        {
            var millerRabinPrimality = new MillerRabinPrimality();

            const ulong total = 1000000ul;

            for (var x = 1ul; x <= total; x++)
            {
                var isMRPrime = millerRabinPrimality.IsPrime(x);
                var isPrime   = MyMath.IsPrime(x);

                if (isMRPrime != isPrime)
                {
                    throw new InvalidOperationException(x.ToString());
                }
            }
        }
Example #4
0
        public void CanCalcPrimalityCorrectlyForBigInteger()
        {
            var millerRabinPrimality = new MillerRabinPrimality();

            const ulong total = 100000ul;

            for (var x = BigInteger.One; x <= total; x++)
            {
                var isMRPrime = millerRabinPrimality.IsPrime(x);
                var isPrime   = MyMath.IsPrime(x);

                if (isMRPrime != isPrime)
                {
                    throw new InvalidOperationException(x.ToString());
                }
            }

            if (!millerRabinPrimality.IsPrime(new BigInteger(5977200007)))
            {
                throw new InvalidOperationException(5977200007.ToString());
            }
        }