Beispiel #1
0
 public LIB_FactorizedNumber(long x)
 {
     foreach (var item in LIB_Math.Factors(x).GroupBy(e => e).ToDictionary(e => e.Key, e => e.LongCount()))
     {
         this[item.Key] = item.Value;
     }
 }
Beispiel #2
0
        static public long Log(long a, long b, int mod)
        {
            var g = 1L;

            for (var i = mod; i != 0; i >>= 1)
            {
                g *= a;
                g %= mod;
            }
            g = LIB_Math.GCD(g, mod);
            var t = 1L;
            var c = 0L;

            for (; t % g != 0; ++c)
            {
                if (t == b)
                {
                    return(c);
                }
                t *= a;
                t %= mod;
            }
            if (b % g != 0)
            {
                return(-1);
            }
            t /= g;
            b /= g;
            var n  = mod / g;
            var h  = 0L;
            var gs = 1L;

            for (; h *h < n; ++h)
            {
                gs *= a;
                gs %= n;
            }
            var bs = new Dictionary <long, long>();

            for (long s = 0L, e = b; s < h; bs[e] = ++s)
            {
                e *= a;
                e %= n;
            }
            for (long s = 0L, e = t; s < n;)
            {
                e *= gs;
                e %= n;
                s += h;
                if (bs.ContainsKey(e) && bs[e] > 0)
                {
                    return(c + s - bs[e]);
                }
            }
            return(-1);
        }
Beispiel #3
0
        void Yakubun()
        {
            if (Denominator < 0)
            {
                Numerator *= -1; Denominator *= -1;
            }
            var gcd = LIB_Math.GCD(Abs(Numerator), Denominator);

            if (gcd == 0)
            {
                Numerator = 0; Denominator = 1;
            }
            else
            {
                Numerator /= gcd; Denominator /= gcd;
            }
        }