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)