示例#1
0
        static void Main(string[] args)
        {
            mpz_t tot = P / 3;

            for (mpz_t roota = 1; roota <= P.Sqrt(); roota++)
            {
                if (roota % 1000 == 0)
                {
                    Console.Write($"\r{roota} : {P.Sqrt()}");
                }
                for (mpz_t rootc = roota + 1; ; rootc++)
                {
                    mpz_t a = roota.Power(2);
                    mpz_t c = rootc.Power(2);
                    mpz_t b = roota.Multiply(rootc);
                    if (a + b + c > P || c > a + b)
                    {
                        break;
                    }
                    //if (mpz_t.Gcd(a, c) == 1)
                    {
                        Console.WriteLine($"{a},{b},{c}  {roota} / {rootc}{(mpz_t.Gcd(a,c) > 1 ? " M" : "")}");
                        tot += P.Divide(a + b + c);
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine(tot);
        }
示例#2
0
        public void Sqrt()
        {
            string AsString;

            using mpz_t a = new mpz_t("95754294066634670780206802290671646680930214410991689632113801");
            AsString      = a.ToString();
            Assert.AreEqual("95754294066634670780206802290671646680930214410991689632113801", AsString);

            mpz_t b = a.Sqrt();

            AsString = b.ToString();
            Assert.AreEqual("9785412309485720938412983404349", AsString);
        }
示例#3
0
        private static mpz_t[] MakeFactors(mpz_t n)
        {
            var allFactors = new List <mpz_t>();
            var factors    = Primes.Where(p => p <= n.Sqrt()).SelectMany(p =>
            {
                var pair        = n.Divide(p, out mpz_t rem);
                var factorsthis = new List <mpz_t>();
                if (rem == 0)
                {
                    factorsthis.Add(p);
                    factorsthis.Add(pair);
                    factorsthis.AddRange(GetFactors(pair));
                }
                return(factorsthis.Distinct().ToArray());
            }).Distinct().ToArray();

            Array.Sort(factors);
            return(factors);
        }