标签:
小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是:
1. 各组的核桃数量必须相同
2. 各组内必须能平分核桃(当然是不能打碎的)
3. 尽量提供满足1,2条件的最小数量(节约闹革命嘛)
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 }
标签:
原文地址:http://www.cnblogs.com/wuqianling/p/5343158.html