コード例 #1
0
        static void Main(string[] args)
        {
            Lint            a          = new Lint("6131066257800");
            PrimeFactorizer factorizer = new PrimeFactorizer(19, 331, 1009, 4663, 6661);

            factorizer.Factorize(a).ForEach(Console.WriteLine);
        }
コード例 #2
0
 private bool CanBeSquare(Lint n)
 {
     for (int i = 0; i < p.Length; i++)
     {
         var yy = n % p[i];
         if (!mods[i][yy])
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #3
0
        public List <Lint> Factorize(Lint n)
        {
            List <Lint> list = new List <Lint>();

            for (; n % 2 == 0; list.Add(2), n /= 2)
            {
                ;
            }

            for (Lint i = 0; ; i++)
            {
                Lint k = n + i * i;
                if (!CanBeSquare(k))
                {
                    continue;
                }

                Lint root = k.SquareRoot();
                if (root * root != k)
                {
                    continue;
                }

                Lint n1 = root - i;
                Lint n2 = root + i;
                if (n1 == 1 || n2 == 1)
                {
                    list.Add(n);
                }
                else
                {
                    list.AddRange(Factorize(n1));
                    list.AddRange(Factorize(n2));
                }

                return(list);
            }
        }