using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Factorizator { static class FactorizatorAlgorithm { public static bool Abort { get; set; } public static void Factorize(decimal number, out decimal[] fact, out decimal[] num) { Abort = false; bool negative = (number < 0); number = Math.Abs(number); List resultFact = new List(); List resultNum = new List(); for (decimal i = 2; i * i <= number && !Abort; i++) { while (number % i == 0) { resultFact.Add(i); if (negative) resultNum.Add(-number); else resultNum.Add(number); number /= i; } } if (negative) resultNum.Add(-number); else resultNum.Add(number); if (number > 1) { if (negative) resultNum.Add(-1); else resultNum.Add(1); resultFact.Add(number); } fact = resultFact.ToArray(); num = resultNum.ToArray(); } } }