小張是軟件項目經理,他帶領3個開發組。工期緊,今天都在加班呢。為鼓舞士氣,小張打算給每個組發一袋核桃(據傳言能補腦)。他的要求是:
1. 各組的核桃數量必須相同
2. 各組內必須能平分核桃(當然是不能打碎的)
3. 盡量提供滿足1,2條件的最小數量(節約鬧革命嘛)
輸入格式 輸入包含三個正整數a, b, c,表示每個組正在加班的人數,用空格分開(a,b,c<30) 輸出格式 輸出一個正整數,表示每袋核桃的數量。 樣例輸入1 2 4 5 樣例輸出1 20 樣例輸入2 3 1 1 樣例輸出2 3 Java源代碼: 1 import java.util.Scanner;
2
3 public class Main {
4
5 public static void main(String[] args) {
6 Scanner in = new Scanner(System.in);
7 int[] a = new int[3];
8 for (int i = 0; i < a.length; i++) {
9 a[i] = in.nextInt();
10 }
11 sort(a);
12 int x = fun(a[0], a[1]);
13 System.out.println(fun(x, a[2]));
14 }
15
16 private static int fun(int x, int y) {
17 int i = x;
18 int j = y;
19 if (i > j) {
20 int t = i;
21 j = i;
22 i = t;
23 }
24 while (i != 0) {
25 int t = j % i;
26 j = i;
27 i = t;
28 }
29 return x * y / j;
30 }
31
32 private static void sort(int[] a) {
33 for (int i = 0; i < a.length - 1; i++) {
34 for (int j = i + 1; j < a.length; j++) {
35 if (a[i] > a[j]) {
36 int x = a[i];
37 a[i] = a[j];
38 a[j] = x;
39 }
40 }
41 }
42 }
43
44 }