[Number of] blue bridge cup walnuts (violence title)

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:

  1. Number of walnuts each group must be the same
  2. Each group must be equally Walnut (of course, not broken)
  3. 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);
		}
	}

}
Published 20 original articles · won praise 0 · Views 3863

Guess you like

Origin blog.csdn.net/weixin_44544406/article/details/104239453