Esempio n. 1
0
        public QuadraticCharacters Build()
        {
            var sieve      = new EratosthenesSieve();
            var primes     = sieve.GetPrimes(_lowerBound + 1, _lowerBound + 100 * _size);
            var derivative = new PolynomialDerivative().Derivative(_polynomial);
            var result     = new List <Pair>();

            List <long> roots;

            for (int i = 0; i < primes.Length; i++)
            {
                roots = _rootFinder.FindRoots(_polynomial, primes[i]);

                for (int j = 0; j < roots.Count; j++)
                {
                    if (derivative.Value(roots[j]) % primes[i] != 0)
                    {
                        result.Add(new Pair(roots[j], primes[i]));
                    }
                    if (result.Count == _size)
                    {
                        return(new QuadraticCharacters(result));
                    }
                }
            }
            return(new QuadraticCharacters(result));
        }
Esempio n. 2
0
        public AlgebraicFactorbase Build()
        {
            var  sieve    = new EratosthenesSieve();
            var  result   = new List <Pair>();
            long interval = 10000000;

            if (_primeBound < interval)
            {
                interval = _primeBound;
            }

            var roots = _rootFinder.FindRoots(_polynomial, 2);

            for (int index = 0; index < roots.Count; index++)
            {
                result.Add(new Pair(roots[index], 2));
            }



            for (long k = 3; k < _primeBound; k += interval)
            {
                var primes = sieve.GetPrimes(k, k + interval);



                for (int i = 0; i < primes.Length; i++)
                {
                    Console.Write("\rAFB building. Current prime: " + primes[i] + "                                 ");
                    roots = _rootFinder.FindRoots(_polynomial, primes[i]);
                    for (int j = 0; j < roots.Count; j++)
                    {
                        result.Add(new Pair(roots[j], primes[i]));
                    }
                }
            }

            return(new AlgebraicFactorbase(result));
        }