Common and public multiples

Source: Internet
Author: User

Common and public multiples

/* It is difficult to describe James's problem. Now you need help. The problem is: two positive integers are given to obtain their maximum common approx. And the least common multiples. Enter an integer n (0 <n <= 10000) In the first line, indicating that there are n groups of test data. Then, input two integers I, j (0 <I, j <= 32767 ). Output the maximum and minimum common multiples of each group of test data. Example: 36 612 1133 22. Example: 6 61 13211 66 * // * Hello, World! 36 6 max common approx.: 6 min. common multiples: 612 11 Max common approx.: 1 min. common multiples: 13233 22 Max common approx.: 11 min. common multiples: 66 */# include <stdio. h> // maximum common approx. int gcd (int a, int B) {if (a <B) return gcd (B, a); else if (B = 0) return a; else return gcd (B, a % B);} // minimum public multiple int lcm (int a, int B) {return a * B/gcd (, b);} int main (int argc, const char * argv []) {// insert code here... printf ("Hello, World! \ N "); int a, B, n; scanf (" % d ", & n); while (n> 0) {scanf (" % d ", & a, & B); printf ("maximum common divisor: % d \ n", gcd (a, B); printf ("minimum common multiple: % d \ n ", lcm (a, B); n --;} return 0 ;}

 

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.