HDU OJ 1108
题目如下:
A - 最小公倍数
Input
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.
Output
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。
Sample Input
10 14
Sample Output
70
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt()){
int a=sc.nextInt();
int b=sc.nextInt();
int s=0;
if(a>b){
int temp=b;
b=a;
a=temp;
}
for(int i=a;i<=a*b;i++) {
if ((i % a == 0) && (i % b == 0)) {
s = i;
break;
}
}
System.out.println(s);
}
}
}
1:交换变量值(a,b)的方法:
(1)使用第三个变量交换:
temp=a;
a=b;
b=temp;
(2)使用异或交换:
a=a^b
b=a^b
a=a^b
来源:CSDN
作者:qq_46040234
链接:https://blog.csdn.net/qq_46040234/article/details/104158879