(python如何计算最大公约数)(python如何计算平均值)

(python如何计算最大公约数)(python如何计算平均值)

正确快速解出答案的关键在于理解要求,清楚其实质要求,达到简化步骤,减少时间的目的。

例2.输出两整数的最大公约数和最小公倍数。

最大公约数:能被两整数同时整除的数,其特点为同时被整除,最小为1,其大小最大为两整数较小的数字。

思路1:从1到较小数遍历,能被整除就记录,并随着遍历的数字变大,该数需更新,保证其为最大公约数。

思路2:两数的最大公约数与其较小的数和原两数的余数的最大公约数相等。故将两数持续更新,直至两数能够整除,则较小的数为最大公约数。

最小公倍数:同时整除两数的最小整数,最大为两数的乘积,最小为两数中最大的数。思路1:从较小的数大两数乘积遍历,能整除则为所求。

思路2:最大公约数和最小公倍数两数的乘积为原两数的乘积,可以这样理解:将两个数字分别写成因式分解的最简形式,最大公约数为两数共有的且数量相同的的数的乘积,而最小公倍数为两数不同时拥和共有一部分(最大公约数)的乘积,故最大公约数和最小公倍数为两数的乘积。

(python如何计算最大公约数)(python如何计算平均值)
(python如何计算最大公约数)(python如何计算平均值)

英文翻译

The key to correctly and quickly solving the answer lies in understanding the requirements, knowing their essential requirements, and achieving the purpose of simplifying steps and reducing time.

Example 2. Output the greatest common divisor and least common multiple of two integers.

Greatest common divisor: a number that can be divisible by two integers at the same time. Its characteristic is that it is divisible at the same time. The smallest is 1, and the largest is the smaller number of the two integers.

Idea 1: Traverse from 1 to a smaller number and record if it can be divisible. As the traversed number becomes larger, the number needs to be updated to ensure that it is the greatest common divisor.

Idea 2: The greatest common divisor of two numbers is equal to the greatest common divisor of its smaller number and the remainder of the original two numbers. Therefore, the two numbers are continuously updated until the two numbers can be divided evenly, and the smaller number is the greatest common divisor.

Least Common Multiple: The smallest integer that divides two numbers at the same time. The largest is the product of the two numbers, and the smallest is the largest of the two numbers.

Idea 1: Traverse the product of two numbers from the smaller number, and divide it evenly.

Idea 2: The product of the greatest common divisor and the least common multiple is the product of the original two numbers. It can be understood as follows: Write the two numbers in the simplest form of factorization, and the greatest common divisor is the same in both numbers The product of the numbers, and the least common multiple is the product of two numbers that do not have and share a part (the greatest common divisor) at the same time, so the greatest common divisor and the least common multiple are the product of two numbers.

参考资料:菜鸟教程

翻译:Google翻译

本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。

声明:我要去上班所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,版权归原作者LearningYard学苑所有,原文出处。若您的权利被侵害,请联系删除。

本文标题:(python如何计算最大公约数)(python如何计算平均值)
本文链接:https://www.51qsb.cn/article/dvjk7n.html

(0)
打赏微信扫一扫微信扫一扫QQ扫一扫QQ扫一扫
上一篇2023-07-29
下一篇2023-07-29

你可能还想知道

发表回复

登录后才能评论