题目
Figure 2 shows the flowchart for an algorithm.
The input for the algorithm is two positive integers.
The function INT(X) is the largest integer less than or equal to X.
(a) Complete the table in the answer book, with and , showing the results at each step of the algorithm.
(b) Explain how the output, , relates to the inputs, and .
题目中文翻译
图 2 显示了算法的流程图。
算法的输入是两个正整数。
函数 INT(X) 是小于或等于 X 的最大整数。
(a) 在答案本中完成表格,取 和 ,显示算法每一步的结果。
(b) 说明输出 与输入 和 的关系。
解答
(a)
解法一
思路
展开
先只计算一次 ,之后沿循环依次计算商 、整数部分 、乘积 与余数 。若 ,用旧的 与余数 更新 ;只有当 时才计算 并输出。
答题过程
展开
Initially,
Following the flowchart gives
| 1980 | 462 | 914760 | 4 | 1848 | 132 | - | |
| 462 | 132 | 914760 | 3 | 396 | 66 | - | |
| 132 | 66 | 914760 | 2 | 132 | 0 | 13860 |
At the final step,
Therefore, the output is
(b)
解法一
思路
展开
循环部分是欧几里得算法:当余数首次变为 0 时,此时的 是两个输入的最大公因数。由于 始终等于两个原输入的乘积,所以输出 等于“乘积除以最大公因数”,即最小公倍数。
答题过程
展开
The loop applies the Euclidean algorithm, so when , the current value of is the highest common factor of the two original inputs.
Since is their product,
Hence is the