Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - public static int[] Factorise(params int[] input)
 - {
 - List<int> output = new List<int>();
 - bool performedAny = false;
 - for (int i = 0; i < input.Length; i++)
 - {
 - int number = Math.Abs(input[i]);
 - bool performedThis = false;
 - for (int j = number - 1; j > 1; j--)
 - {
 - if (number % j == 0)
 - {
 - output.Add(j);
 - output.Add(number / j);
 - performedThis = true;
 - performedAny = true;
 - break;
 - }
 - }
 - if (!performedThis)
 - {
 - output.Add(number);
 - }
 - }
 - output.Sort();
 - int[] outArray = output.ToArray();
 - if (input.Length > 0 && input[0] < 0)
 - {
 - outArray[0] = -outArray[0];
 - }
 - return performedAny ? Factorise(outArray) : outArray;
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment