C language · The number of walnuts

Source: Internet
Author: User
Tags gcd greatest common divisor

Number of previous questions Walnut quantity time limit: 1.0s memory limit: 256.0MBBrocade SAC 1 least common multiple. Kam SAC 2 The answer is a, B, c least common multiple. 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 format input contains three positive integers a, B, C, indicating the number of people each group is working overtime, output a positive integer in a space-separated (a,b,c<30) output format, indicating the number of walnuts per bag. Sample Input 12 4 5 Sample output 120 Sample input 23 1 1 Sample output 23
1 /*2 least common multiple = Two integer of the Product ÷ greatest common divisor;3 */4#include <stdio.h>5 //recursive seeking greatest common divisor6 intgcdintMintN)7 {  8     returnn==0? M:GCD (n,m%N); 9 }Ten //seeking greatest common divisor by phase subtraction One intGCD2 (intAintb) { A      while(a!=b) { -         if(a>b) { -A = A-b; the}Else { -b = BetaA; -         } -     } +     returnA//Greatest common divisor is a or B - } + intMain () { A     inta,b,c; atscanf"%d%d%d",&a,&b,&c); -     intMin1 = (a*b)/gcd2 (A, b);//the least common multiple of a and B -     intMin2 = (min1*c)/gcd2 (MIN1,C);//least common multiple of a, B and C -printf"%d", min2); -}

C language · The number of walnuts

Related Article

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.