Algorithmic Note _182: Number of walnuts in previous questions (Java)

Source: Internet
Author: User

Directory

1 Problem Description

2 Solutions

 

1 problem description Problem Description

Xiao Zhang is a software project manager and he leads 3 development teams. The schedule is tight and it's working overtime today. To inspire morale, Xiao Zhang intends to send a sack of walnuts to each group (according to rumors Brain). His requirements are:

1. The number of walnuts in each group must be the same

2. Walnuts must be evenly divided within each group (not broken, of course)

3. Try to provide the minimum quantity to meet the conditions (save Revolution)

Input FormatThe input contains three positive integers a, B, C, indicating the number of people each group is working overtime, separated by a space (a,b,c<30)output Formatoutputs a positive integer that indicates the number of walnuts per bag. Sample Input 12 4 5Sample Output 1 -Sample Input 23 1 1Sample Output 23

2 Solutions

The specific code is as follows:

ImportJava.util.Scanner; Public classMain { Public intGETGCD (intNintm) {returnm = = 0? N:GETGCD (m, n%m); }         Public voidGetResult (intAintBintc) {intlcmab = A * B/GETGCD (a, b);//the least common multiple of a and B        intresult = lcmab * C/GETGCD (lcmab, C);//lcmab and C's least common multipleSystem.out.println (Result); }             Public Static voidMain (string[] args) {main test=NewMain (); Scanner in=NewScanner (system.in); intA =In.nextint (); intb =In.nextint (); intc =In.nextint ();    Test.getresult (A, B, c); }}

Algorithmic Note _182: Number of walnuts in previous questions (Java)

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.