求公约数和公倍数

输入不受限制

用欧几里得的辗转相除求最大公约数

加公倍数。

#include<iostream>
#include<cstdio>
using namespace std;
void yue(int a,int b)
{
    int temp=b;
    while(temp>0)
    {
        temp=a%b;
        a=b;
        b=temp;
    }
    cout<<a<<" ";
}
void bei(int a,int b)
{
    int temp;
    temp=a>b?a:b;
    for(;temp<=a*b;temp++)
    {
        if(temp%a==0&&temp%b==0)
        {
            cout<<temp<<endl;
            break;
        }
    }
    
}
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        yue(a,b);
        bei(a,b);
    }
    
    return 0;
}
原文地址:https://www.cnblogs.com/tt-t/p/5059668.html