[Blue Bridge Cup] Number of previous questions about walnut, Blue Bridge previous questions about walnut
Number of walnuts for previous questionsTime Limit: 1.0 s memory limit: 256.0 MB
Problem description
Mr. Zhang is the software project manager and leads three development teams. Due to a tight schedule, we are working overtime today. To boost morale, Mr. Zhang plans to send a bag of walnuts to each group (it is rumored that the bag can be supplemented ). His requirements are:
1. The number of walnuts in each group must be the same
2. Each group must be able to divide the walnut equally (of course, it cannot be broken)
3. Try to provide the minimum number that meets 1 or 2 conditions (saving the Revolution)
Input FormatThe input contains three positive integers a, B, and c, indicating the number of overtime workers in each group, separated by spaces (a, B, c <30)
Output FormatThe output is a positive integer indicating the number of walnuts per bag.
Example input 12 4 5
Sample output 120
Sample input 23 1 1
Sample output 23
Java source code:
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 }
Evaluation point No. |
Evaluation Result |
Score |
CPU usage |
Memory usage |
Download evaluation data |
1 |
Correct |
50.00 |
187 ms |
23.35 MB |
Input and Output |
2 |
Correct |
50.00 |
156 ms |
23.39 MB |
Input and Output |