Title Description
Zhang is a software project manager, he led three development groups. Tight schedule today in overtime it. To boost morale, Zhang intends to send a bag of walnuts (rumored to be able to nourish the brain) to each group. His requirements are:
- Number of walnuts each group must be the same
- Each group must be equally Walnut (of course, not broken)
- Try to provide a minimum number satisfying the condition of 1 (saving revolution Well)
Input
Input contains three positive integers a, b, c, represents the number of each group is overtime, separated by a space (a, b, c <30 )
outputs
output a positive integer representing the number of bag walnut.
Sample input
245
sample output
20
Problem-solving ideas
Is seeking the least common multiple of the number three, violence can be solved
package 核桃的数量;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
int c=in.nextInt();
int x=gcd(a,b);
int y=a*b/x;
int z=gcd(y,c);
int d=y*c/z;7
System.out.println(d);
}
public static int gcd(int a,int b)
{
if(b==0)
return a;
else
{
return gcd(b,a%b);
}
}
}