public static CountSystem GetNewOrder(int inOrder, CountSystem inCS) { if (inOrder > 45000) { inOrder = 45000; } if (inOrder < 2) { inOrder = 2; } CountSystem newOne = new CountSystem(inOrder); CountSystem retCS = new CountSystem(inOrder); for (int i = 0; i < inCS.MyValue.Count; ++i) { newOne.MyValue.Clear(); newOne.MyValue.Add(inCS.MyValue[i]); for (int ii = 0; ii < i; ++ii) { newOne.MultByInt(inCS.myOrder); } retCS.SelfSum(newOne); } return(retCS); }
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); }