Beispiel #1
0
 public static cpolinom CreateRand(int n, int m)
 {
     cpolinom c = new cpolinom("", m);
     for (int i = 0; i < n; i++)
         c.Add(Mod(r.Next(), m));
     while (c[0] == 0)
         c.RemoveAt(0);
     return c;
 }
Beispiel #2
0
 private static void Fix(cpolinom p)
 {
     while (p[0] == 0 && p.Count != 0)
         p.RemoveAt(0);
     if (p.Count == 0) p.Add(0);
 }
Beispiel #3
0
 public static cpolinom Copy(cpolinom a)
 {
     cpolinom t = new cpolinom("", a.mod);
     for (int i = 0; i < a.Count; i++)
         t.Add(a[i]);
     return t;
 }
Beispiel #4
0
        public static cpolinom operator /(cpolinom a, cpolinom b)
        {
            cpolinom np = new cpolinom("", Math.Max(a.mod, b.mod));
            cpolinom t = Copy(a);

            int m;
            while (t.Count >= b.Count)
            {
                m = Coef(t[0], b[0], t.mod);
                if (m == 0) m = Mod(t[0] / b[0], t.mod);
                for (int i = 0; i < b.Count; i++)
                    t[i] = Mod(t[i] - m * b[i], t.mod);
                t.RemoveAt(0);
                np.Add(m);
            }

            return np;
        }
Beispiel #5
0
        public static cpolinom operator *(cpolinom a, cpolinom b)
        {
            cpolinom np = new cpolinom("", Math.Max(a.mod, b.mod));
            cpolinom t;

            for (int i = 0; i < a.Count; i++)
                np.Add(a[i] * b[0]);

            for (int i = 1; i < b.Count; i++)
            {
                t = new cpolinom("", Math.Max(a.mod, b.mod));
                for (int j = 0; j < a.Count; j++)
                    t.Add(a[j] * b[i]);
                np.Add(0);
                np = np + t;
            }

            if (np.x.Count == 0)
                np.Insert(0, 0);
            while (np[0] == 0 && np.Count > 1)
                np.RemoveAt(0);

            return np;
        }
Beispiel #6
0
 public static cpolinom operator -(cpolinom a, cpolinom b)
 {
     cpolinom np = new cpolinom("", Math.Max(a.mod, b.mod));
     while (a.Count < b.Count)
         a.Insert(0, 0);
     while (b.Count < a.Count)
         b.Insert(0, 0);
     for (int i = 0; i < a.Count; i++)
         np.Add(Mod(a[i] - b[i], np.mod));
     return np;
 }