最小公倍数
来源:互联网 发布:算法工程师考试时间 编辑:程序博客网 时间:2024/05/19 09:40
算法训练 5-1最小公倍数
时间限制:1.0s 内存限制:256.0MB
问题描述
编写一函数lcm,求两个正整数的最小公倍数。
样例输入
一个满足题目要求的输入范例。
例:
3 5
例:
3 5
样例输出
与上面的样例输入对应的输出。
例:
例:
数据规模和约定
输入数据中每一个数的范围。
例:两个数都小于65536。
例:两个数都小于65536。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
int c=a*b;
if(a<b){
int temp=a;
a=b;
b=temp;
}
int r=a%b;
while(r!=0){
a=b;
b=r;
r=a%b;
}
System.out.println(c/b);
}
}
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
int c=a*b;
if(a<b){
int temp=a;
a=b;
b=temp;
}
int r=a%b;
while(r!=0){
a=b;
b=r;
r=a%b;
}
System.out.println(c/b);
}
}
0 0
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- 最小公倍数
- MAC 查看java home目录
- Java高并发设计——并行程序基础二
- MVP
- 关于CRF序列标注的一些理解
- java.lang.SecurityException: Can't make field constructor accessible
- 最小公倍数
- 我的CSDN第一天
- php复习 第八天 日期与时间函数
- Android 应用中验证码登陆都有哪些实现方案
- uva10304 Optimal Binary Search Tree
- String.Int.char转换
- 获取当前的系统路径以及将项目部署到Tomcat服务器上
- MyBank系统
- swift 地图定位(一)