Q:如何对整数N分解质因数?
A:一般是循环2-SQRT(N)间的素数去试除N.这里提供一个利用网络资源分解质因数的方法;
Function Numberfactorizer(ByVal number As String) As String If number Like "*[!0-9]*" Then Exit Function '非数字 If Len(number) > 49 Then Exit Function '大于10^50 With CreateObject("Microsoft.XmlHttp") .Open "get", "http://www.numberempire.com/numberfactorizer.php?number=" & number, False .send Numberfactorizer = number & "=" & Split(Split(.responsetext, "Factorization: ")(1), "</div>")(0) End With End Function Sub Test() Debug.Print Numberfactorizer("5496798436872018423594784658472398479365743653457") End Sub
代码返回:5496798436872018423594784658472398479365743653457=631*2203*363855034465310413*10867698146089328508354473