Two numbers of greatest common divisor and least common multiple

Source: Internet
Author: User
Tags greatest common divisor

Several integers, the public ones, are called the number of conventions, the largest of which is called the greatest common divisor of these few numbers. For example: 12, 16 of the number of conventions have ± 1, ± 2, ±4, the largest one is the greatest common divisor of 12 and 16, generally recorded as (12,16) = 4. 12, 15, 18 of the greatest common divisor is 3, recorded as (12,15,18) = 3.
Several natural numbers of public multiples, called these numbers of common multiple, of which the smallest of a natural number, called these several numbers of least common multiple. For example: Multiples of 4 have ±4, ±8, ±12, ±16,......,6 multiples of ±6, ±12, ±18, ±24,......,4 and 6 common multiple have ±12, ±24, ..., the smallest of which is 12, generally recorded as [4,6] = 12. 12, 15, 18 of the least common multiple is 180. Recorded as [12,15,18] = 180. The least common multiple of several Inma is the absolute value of their product. */
By concept: These few numbers in the Convention can be positively negative, greatest common divisor is positive common multiple, the numbers must be positive, the result is positive

#define  _CRT_SECURE_NO_WARNINGS 1#include<stdio.h> #include <stdlib.h> #include <assert.h >int maxdiv (int div1, int div2) { //idea: the Euclidean method (and the more subtractive method),  aka Euclidean algorithm (Euclidean &NBSP;ALGORITHM) is an algorithm for finding the largest common factor of two positive integers. It is known as the oldest algorithm,  it dates back to 3000 ago.  //first, two numbers must be the same as positive  assert (DIV1);  assert (DIV2);  int rem = div1%div2; while   (REM&NBSP;=&NBSP;DIV1%DIV2)  {  div1 = div2;  div2 = rem;  } return div2;} Int minmul (INT&NBSP;MUL1,&NBSP;INT&NBSP;MUL2) { //idea: the product of two number divided by two number of greatest common divisor  assert (MUL1);  assert ( MUL2);  return mul1*mul2 / maxdiv (MUL1,&NBSP;MUL2);} Void test () { int a = 0, b = 0; scanf ("%d",  &a);  scanf ("%d",  &b),  printf ("maxdiv = %d\n",  maxdiv (A, b));  printf ("MinMul  = %d\n ",  minmul (A, b));} Int main () { test ();  sYstem ("pause");  return 0;} 


Two numbers of greatest common divisor and least common multiple

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.