public void SelfDiv(CountSystem inCS) { CountSystem inSecond = inCS; if (myOrder != inCS.myOrder) { inSecond = GetNewOrder(myOrder, inCS); } CountSystem retCS = new CountSystem(myOrder); CountSystem testCS = new CountSystem(myOrder); CountSystem localCS = new CountSystem(myOrder); for (int i = 1; i < inSecond.MyValue.Count; ++i) { testCS.MyValue.Add(MyValue[MyValue.Count - inSecond.MyValue.Count + i]); } for (int i = MyValue.Count - inSecond.MyValue.Count; i >= 0; --i) { testCS.MyValue.Insert(0, MyValue[i]); if (testCS < inSecond) { retCS.MyValue.Add(0); continue; } else { int Min = 1; int Max = myOrder; while (Max - Min > 1) { int Mid = (Max + Min) / 2; localCS.SetValue(inSecond); localCS.MultByInt(Mid); if (localCS <= testCS) { Min = Mid; if (localCS == testCS) { break; } } else { Max = Mid; } } localCS.SetValue(inSecond); localCS.MultByInt(Min); testCS.SelfSub(localCS); retCS.MyValue.Add(Min); } } retCS.MyValue.Reverse(); retCS.Normalize(); MyValue = retCS.MyValue; }
public static CountSystem operator /(CountSystem inCSfirst, CountSystem inCSsecond) { CountSystem inSecond = inCSsecond; if (inCSfirst.myOrder != inCSsecond.myOrder) { inSecond = GetNewOrder(inCSfirst.myOrder, inCSsecond); } CountSystem retCS = new CountSystem(inCSfirst.myOrder); CountSystem testCS = new CountSystem(inCSfirst.myOrder); CountSystem localCS = new CountSystem(inCSfirst.myOrder); for (int i = 1; i < inSecond.MyValue.Count; ++i) { testCS.MyValue.Add(inCSfirst[inCSfirst.MyValue.Count - inSecond.MyValue.Count + i]); } for (int i = inCSfirst.MyValue.Count - inSecond.MyValue.Count; i >= 0; --i) { testCS.MyValue.Insert(0, inCSfirst.MyValue[i]); if (testCS < inSecond) { retCS.MyValue.Add(0); continue; } else { int Min = 1; int Max = inCSfirst.myOrder; int Mid = (Max + Min) / 2; while (Max - Min > 1) { Mid = (Max + Min) / 2; localCS.SetValue(inSecond); localCS.MultByInt(Mid); if (localCS <= testCS) { Min = Mid; if (localCS == testCS) { break; } } else { Max = Mid; } } retCS.MyValue.Add(Min); localCS.SetValue(inSecond); localCS.MultByInt(Min); testCS.SelfSub(localCS); } } retCS.MyValue.Reverse(); retCS.Normalize(); return(retCS); }