JAVA_最大公約數與最小公倍數

最大公約數與最小公倍數

Time Limit: 1000MS Memory Limit: 65536KB
 

Problem Description

輸入兩個整數,求它們的最大公約數與最小公倍數。

Input

輸入兩個整數,兩個整數之間用空格分開。

Output

第一行輸出最大公約數;
第二行輸出最小公倍數。

Example Input

64 48

Example Output

16
192


01 import java.util.*;
02 import java.lang.*;
03 public class Main {
04     public static void main(String args[]){
05     Scanner input = new Scanner(System.in);
06     int a = input.nextInt();
07     int b = input.nextInt();
08     int n = a*b;
09     int b1 =b;
10     while(b!=0){
11         if(b!=0){
12             b1 = b;
13         }
14          
15         b = a%b;
16     }
17     System.out.println(b1);
18     System.out.println(n/b1);
19 }
20 }
21  





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章