Common Divisor and public multiple

Source: Internet
Author: User
Common Divisor and public multiple

DescriptionJames was troubled by a problem. Now I need your help. The problem is: two positive integers are given to obtain their maximum common approx. And the least common multiples.

 
Input
Enter an integer N (0 <n <= 10000) in the first row, indicating that there are N groups of test data. Then, input two integers I, j (0 <I, j <= 32767 ).
Output
Output the maximum and least common multiples of each group of test data
Sample Input
36 612 1133 22
Sample output
6 61 13211 66

 #include<iostream>using namespace std;int gcd(int a,int b){    int min=(a<b)?a:b;    int max=(a>b)?a:b;    while(min!=0)    {    int k = max%min;    max=min;    min=k;    }    return max;}int main(){    int test ;    int num1,num2;    cin>>test;    while(test--)    {        cin>>num1>>num2;        int kk = (num1 * num2)/gcd(num1,num2);        cout<<gcd(num1,num2)<<" "<<kk<<endl;    }    return 0;}        

 

Common Divisor and public 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.