题解 | #求最小公倍数#

求最小公倍数

http://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3

import java.io.; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = in.readLine()) != null){ String[] arr = str.split(" "); int a = Integer.parseInt(arr[0]); int b = Integer.parseInt(arr[1]); System.out.println(ab/gdb(a,b)); } } public static int gdb(int a,int b){ if(a < b){ int temp = a; a = b; b = temp; } while(a % b != 0){ int temp = b; b = a % b; a = temp; } return b;

}

}

我居南半坡 文章被收录于专栏

多刷题,积蓄力量,欢迎讨论

全部评论

相关推荐

点赞 评论 收藏
分享
10-09 16:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务