Public Function factor(a, b, c) answerString = "" needNegativeSign = False If a < 0 Then needNegativeSign = True a = a*(-1) b = b*(-1) c = c*(-1) End If product = Abs(a * c) If c = 0 Then n = gcf(Abs(a), Abs(b)) answerString = n & "*x*(" & (a / n) & "*x + " & (b / n) & ")" answerString = Replace(answerString, "+ -", "- ") Else For i = 1 to int(sqr(product)) If product Mod i = 0 Then n1 = i n2 = product / i If c < 0 Then If n1 - n2 = b Then GCF1 = gcf(a, n1) GCF2 = gcf(n2, c) answerString = "(" & GCF1 & "*x - " & GCF2 & ")*(" & (a / GCF1) & "*x + " & (n1 / GCF1) & ")" Exit For ElseIf n2 - n1 = b Then GCF1 = gcf(a, n1) GCF2 = gcf(n2, c) answerString = "(" & GCF1 & "*x + " & GCF2 & ")*(" & (a / GCF1) & "*x - " & (n1 / GCF1) & ")" Exit For End If Else If n1 + n2 = b Or n1 + n2 = -b Then GCF1 = gcf(a, n1) GCF2 = gcf(n2, c) answerString = "(" & GCF1 & "*x + " & GCF2 & ")*(" & (a / GCF1) & "*x + " & (n1 / GCF1) & ")" If n1 + n2 = -b Then answerString = Replace(answerString, "+", "-") End If Exit For End If End If End If Next End If If answerString <> "" Then answerString = replace(answerString, "(-1*", "(") answerString = replace(answerString, "(1*", "(") answerString = replace(answerString, "*", "") If needNegativeSign Then answerString = "-" + answerString End If factor = answerString Else factor = "cannot factor" End If End Function