YAMP.Numerics.Fourier.FactorByPollardsRhoMethod C# (CSharp) Method

FactorByPollardsRhoMethod() static private method

static private FactorByPollardsRhoMethod ( List factors, int &n ) : void
factors List
n int
return void
        static void FactorByPollardsRhoMethod(List<Factor> factors, ref int n)
        {
            int x = 5;
            int y = 2;
            int k = 1;
            int l = 1;

            for (int c = 0; c < 250; c++)
            {
                int g = Helpers.GCD(Math.Abs(y - x), n);

                if (g == n)
                    return;
                else if (g == 1)
                {
                    k--;

                    if (k == 0)
                    {
                        y = x;
                        l = 2 * l;
                        k = l;
                    }

                    x = Helpers.PowMod(x, 2, n) + 1;
                    if (x == n) x = 0;
                }
                else
                {
                    int m = 0;

                    while (n % g == 0)
                    {
                        n = n / g;
                        x = x % n;
                        y = y % n;
                        m++;
                    }

                    factors.Add(new Factor(g, m));
                }
            }
        }