如果我可以成对获得因子,那么我只需要循环到该数字的平方根。
I only need to go up to the square root of the number if I can harvest the factors in pairs. To that end, I improve the algorithm and refactor the code to Listing 3.
假设我们希望得到这样一个查找表:它返回5到20之间各个数字的平方根。
Let's say you want a lookup table that will return square roots of Numbers between 5 and 20. A simple program can be written to generate such a table like this.
清单5中的代码首先将该因子列表收集到目标数字的平方根,将其保存在factor变量中。
The code in Listing 5 first gathers the list of factors up to the square root of the target number, saving it in the factors variable.
应用推荐