예제 #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
        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);
        }