public static List <SpliedNumber> Split(Int64 integer) { Int64 abs = integer < 0 ? -integer : integer; List <SpliedNumber> temp = new List <SpliedNumber>(); for (Int64 i = -abs; i <= abs; i += 1) { SpliedNumber spliedNumber = new SpliedNumber(); if (i == 0) { continue; } if (integer % i == 0) { spliedNumber.num1 = i; spliedNumber.num2 = integer / i; temp.Add(spliedNumber); } } return(temp); }
public static Boolean Factorization(Pylonomial list, out Product product) { if (list.moList.Count == 3 && (list.moList[0].Letters[0].Exponent == 2)) { Boolean sig = true; if (list.moList[0].Coefficient < 0) { list.ChangeSign(); sig = false; } Char letter = list.moList[0].Letters[0].GetLetter; List <SpliedNumber> list1 = Split((Int64)list.moList[0].Coefficient); List <SpliedNumber> list2 = Split((Int64)list.moList[2].Coefficient); List <Int64> list3 = new List <Int64>(); foreach (var i in list1) { foreach (var j in list2) { if ((i.num1 * j.num2 + i.num2 * j.num1) == (Int64)list.moList[1].Coefficient) { SpliedNumber ti = i, tj = j; Boolean sign = true; if (ti.num1 < 0 && ti.num2 < 0) { ti.num1 = -ti.num1; ti.num2 = -ti.num2; tj.num1 = -tj.num1; tj.num2 = -tj.num2; } else if (ti.num1 < 0 && ti.num2 > 0) { ti.num1 = -ti.num1; tj.num1 = -tj.num1; sign = false; } else if (ti.num1 > 0 && ti.num2 < 0) { ti.num2 = -ti.num2; tj.num2 = -tj.num2; sign = false; } product = new Product(); if (sig == sign) { product.IsPositive = true; } else { product.IsPositive = false; } product.Add(new Pylonomial((ti.num1 == 1 ? "" : ti.num1.ToString()) + letter + (tj.num1 < 0 ? tj.num1.ToString() : "+" + tj.num1.ToString()))); product.Add(new Pylonomial((ti.num2 == 1 ? "" : ti.num2.ToString()) + letter + (tj.num2 < 0 ? tj.num2.ToString() : "+" + tj.num2.ToString()))); return(true); } } } product = new Product(); return(false); } product = new Product(); return(false); }