[Blue Bridge Cup] Number of previous questions about walnut, Blue Bridge previous questions about walnut

Source: Internet
Author: User

[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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.