首页 > 编程知识 正文

最大公约数和最小公倍数算法,最小公倍数公式法

时间:2023-05-04 00:28:02 阅读:39594 作者:3362

最小公倍数=两数之积/最大公约数

所以求最小公倍数就是掌握最大公约数的算法:

用换相除法求出两个个数的最大公约数

import shijian3.waiguan.Light; import java.util.*; public class main { publicstaticintgetmaxyinzi (inta,int b ) if ) b==0)返回a; ELSE{returngetmaxyinzi(b,a%b ); } publicstaticvoidmain (字符串[ ] args ) scannersc=newscanner ) system.in ); while(sc.Hasnext () ) {int a=sc.nextInt; int b=sc.nextInt (; system.out.println (a* b/getmaxyinzi (a,b ); } }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。